Quantcast
Channel: Active questions tagged kernel - Stack Overflow
Viewing all articles
Browse latest Browse all 6333

Linux kernel fatal exception (alignment trap)

$
0
0

I am trying to get into kernel programming a bit. I would like to try and print out processes in run queues on each CPU when a specific kernel panic occurs. I have been looking at various code chunks in kernel and tried to emulate the same in my own fashion, but I guess I made some kind of Frankenstein that results in fatal exception and alignment trap:

int cpu = 0;
struct rq *rq;
struct task_struct *p, *n;

for_each_possible_cpu(cpu) {
    rq = cpu_rq(cpu);
    raw_spin_lock(&rq->lock);
    printk(KERN_INFO, "rq->nr_running=%u\n", nr_running);
    list_for_each_entry_safe(p, n, &rq->cfs_tasks, se.group_node) {
        printk(KERN_INFO, "%d : %s\n", p->pid, p->comm);
    }
    raw_spin_unlock(&rq->lock);
};

The loop executes for only CPU 0, and then it goes crazy. Can you point me in the right direction? (This is code I wrote in core.c)

Edit: The problem is in the spinlock. I would guess that only process being run on that CPU can take a lock?

Edit2: It seems I got it to work. I think the problem was that, in the original source code, struct rq* rq declaration was inside the for loop.


Viewing all articles
Browse latest Browse all 6333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>