Ramsey Alsheikh
Ramsey Alsheikh

Reputation: 329

printk works in some functions but not all

I am writing a system call for the Linux kernel, and as of yet it's not working as I intended it to (no surprise there). I'm trying to use printk messages to debug it in one function, but they arent working. Yet, the ones in a separate function do work.

I've tried using pr_info instead of printk, but that hasn't worked. I've used mdelay instead of msleep, which didn't help.

printk doesn't work in dq_update (called in sys_delta), but it does work in dq_print.

typedef struct _delta_entry
{
    struct task_struct *task;
    struct list_head list;
    int delta_time;
} delta_entry;
void dq_print(delta_entry* head)
{
    delta_entry* pos;
    printk("dq_print: ");

    list_for_each_entry(pos, &head->list, list)
    {
        printk("[%d] ", pos->delta_time);
    }

    printk("\n");
}
void dq_update(struct list_head *delta_queue)
{
    //find and store the root
    delta_entry *root = list_entry(delta_queue -> prev, delta_entry, list);

    //decrement its delta time
    pr_info("DECREMENTING ROOT FROM %d", root->delta_time);
    root -> delta_time -= 1;
    pr_info("DONE DECREMENTING ROOT: AT %d", root->delta_time);

    //remove it if its waiting is done, and any subsequent processes that were waiting for the same time
    for (root; root->delta_time <= 0 && root != delta_queue; root = list_entry(root->list.prev, delta_entry, list))
    {
    wake_up_process(root->task);
        delta_queue -> prev = delta_queue -> prev -> prev;
    delta_queue -> prev -> next = delta_queue;
    }
}
asmlinkage long sys_delta(void)
{
    int sleep_times[] = {532, 58, 542, 573, 924, 379, 753, 183, 268, 254, 803, 188, 794, 936, 976, 585, 755, 189, 905, 880, 911, 396, 889, 348, 629, 515, 830, 107, 452, 47, 857, 650, 14, 524, 548,                     476, 551, 953, 366, 572, 419, 450, 134, 748, 944, 904, 557, 651, 788, 92, 982, 901, 11, 5, 72, 798, 447, 658, 843, 445, 204, 380, 392, 385, 199, 426, 474, 139, 404, 274, 511,                      74, 540, 244, 827, 330, 342, 598, 487, 206, 606, 261, 81, 772, 603, 323, 920, 430, 67, 316, 706, 801, 716, 307, 703, 657, 228, 712, 434, 898};

    delta_entry head = {NULL, LIST_HEAD_INIT(head.list), NULL};

    delta_entry entries[100];
    int i;


    for (i = 0; i < 100; i++)
    {
        delta_entry de = {make_thread(sleep_times[i]), LIST_HEAD_INIT(de.list), sleep_times[i]};
        entries[i] = de;
        dq_add(&entries[i], entries[i].delta_time, &head);
    }

    i = 1;

    do
    {
        mdelay(1);
        dq_update(&head.list);
        i++;
    }
    while (dq_size(&head.list) > 0);


    dq_print(&head);

    return 0;

}

I know this is a lot of code, sorry if I posted too much or if this question is a bad one. Thank you for your help!

Upvotes: 0

Views: 251

Answers (1)

O.logN
O.logN

Reputation: 336

If code of dq_update() is really executed, then probably you call printk with too low priority. Either increase kernel log level by running "echo 8 > /proc/sys/kernel/printk" from root shell, or add log level to printk() calls like: printk(KERN_EMERG "Important message"); You can see list of possible log level values in : include/linux/kern_levels.h

Upvotes: 1

Related Questions