簡體   English   中英

排序內核linux鏈表

[英]Sorting kernel linux linked list

我有一個C程序,用於模擬不同的調度算法。 從文件中讀取過程信息。 文件中的每個進程信息都存儲在以下結構中:

struct task_struct {
  volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
  unsigned int flags; /* per process flags, defined below */
  int on_rq;
  int prio, static_prio, normal_prio;
  const struct sched_class *sched_class;
  struct list_head tasks;
  pid_t pid;
  int arr;
  /* simplify accounting */
  int ticks;
  int start_tick;
  int end_tick;
  int burst;
};

我有一個“隊列”結構,它將保存任務/進程列表

struct rq {
  struct task_struct *curr, *idle, *stop;
  struct list_head task_root;
};

我有點理解內核鏈表如何工作並擁有list.h的用戶版本。 似乎大多數與列表的交互都是在list.h中定義的。 任何人都有一個想法,如何嘗試使用該文件中的函數實現排序算法(可能合並)?

為什么不直接使用list_sort中定義linux/list_sort.h 語法是:

/**
 * list_sort - sort a list
 * @priv: private data, opaque to list_sort(), passed to @cmp
 * @head: the list to sort
 * @cmp: the elements comparison function
 *
 * This function implements "merge sort", which has O(nlog(n))
 * complexity.
 *
 * The comparison function @cmp must return a negative value if @a
 * should sort before @b, and a positive value if @a should sort after
 * @b. If @a and @b are equivalent, and their original relative
 * ordering is to be preserved, @cmp must return 0.
 */
void list_sort(void *priv, struct list_head *head,
        int (*cmp)(void *priv, struct list_head *a,
            struct list_head *b))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM