[<prev] [next>] [day] [month] [year] [list]
Message-ID: <CAN2J1_ObiGJnwdcEfEmrX4tyX+xEaf_Xz4cc-wmC+aCaeWr4MA@mail.gmail.com>
Date: Sat, 19 Mar 2016 01:06:26 +0200
From: nad gam <nadavkernel@...il.com>
To: linux-kernel@...r.kernel.org
Subject: whats wrong with my code ? trying to lock and iterate through read
tasks in cfs rq
here is the code of system call I implemented trying to iterate
through cfs tasks of cpu_num rq and retrieve their pids :
#include <linux/kernel.h>
#include <linux/sched.h>
#include "/home/user/linux-3.14.1/kernel/sched/sched.h"
#include <linux/slab.h>
#include <asm/uaccess.h>
asmlinkage long sys_get_tasks_from_rq(int cpu_num,void* dst)
{
struct rq * my_rq;
my_rq=cpu_rq(cpu_num);
int* pids = (int*) kmalloc(sizeof(int)*my_rq->nr_running,GFP_KERNEL);
struct task_struct *p, *n;
int i=0;
raw_spin_lock_irq(&my_rq->lock);
list_for_each_entry_safe(p, n, &my_rq->cfs_tasks, se.group_node){
pids[i]=task_pid_vnr(p);
i++;
}
raw_spin_unlock_irq(&my_rq->lock);
copy_to_user(dst,pids,300);
return 0;
}
when I try to use it in user space I get segmenation fault :
int main(int argc,char** argv){
int cpuNum = atoi(argv[1]);
int pids[300];
syscall(319,cpuNum,pids);
int i;
for (i=0;i<10;i++){
printf("%d \t",pids[i]);
}
}
So I guess Im doing something wrong :/ Could some plz direct me for
where my problem is? Thanks !
Powered by blists - more mailing lists