gpt4 book ai didi

c - printk 适用于某些功能但不是全部

转载 作者:太空宇宙 更新时间:2023-11-04 09:59:32 24 4
gpt4 key购买 nike

我正在为 Linux 内核编写一个系统调用,但到目前为止它并没有像我预期的那样工作(这并不奇怪)。我正在尝试使用 printk 消息在一个函数中对其进行调试,但它们不起作用。然而,单独功能中的功能确实有效。

我试过使用 pr_info 而不是 printk,但是没有用。我使用了 mdelay 而不是 msleep,这没有帮助。

printk 在 dq_update 中不起作用(在 sys_delta 中调用),但它在 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;

}

我知道这是很多代码,如果我发布的太多或者这个问题不好,我深表歉意。感谢您的帮助!

最佳答案

如果 dq_update() 的代码真的被执行了,那么可能你调用 printk 的优先级太低了。通过从 root shell 运行“echo 8 >/proc/sys/kernel/printk”来增加内核日志级别,或者将日志级别添加到 printk() 调用,例如:printk(KERN_EMERG "重要信息");您可以在以下位置查看可能的日志级别值列表: include/linux/kern_levels.h

关于c - printk 适用于某些功能但不是全部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57499217/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com