// SPDX-License-Identifier: GPL-2.0-or-later /* * lib/plist.c * * Descending-priority-sorted double-linked list * * (C) 2002-2003 Intel Corp * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>. * * 2001-2005 (c) MontaVista Software, Inc. * Daniel Walker <dwalker@mvista.com> * * (C) 2005 Thomas Gleixner <tglx@linutronix.de> * * Simplifications of the original code by * Oleg Nesterov <oleg@tv-sign.ru> * * Based on simple lists (include/linux/list.h). * * This file contains the add / del functions which are considered to * be too large to inline. See include/linux/plist.h for further * information.
*/
/** * plist_del - Remove a @node from plist. * * @node: &struct plist_node pointer - entry to be removed * @head: &struct plist_head pointer - list head
*/ void plist_del(struct plist_node *node, struct plist_head *head)
{
plist_check_head(head);
if (!list_empty(&node->prio_list)) { if (node->node_list.next != &head->node_list) { struct plist_node *next;
next = list_entry(node->node_list.next, struct plist_node, node_list);
/* add the next plist_node into prio_list */ if (list_empty(&next->prio_list))
list_add(&next->prio_list, &node->prio_list);
}
list_del_init(&node->prio_list);
}
list_del_init(&node->node_list);
plist_check_head(head);
}
/** * plist_requeue - Requeue @node at end of same-prio entries. * * This is essentially an optimized plist_del() followed by * plist_add(). It moves an entry already in the plist to * after any other same-priority entries. * * @node: &struct plist_node pointer - entry to be moved * @head: &struct plist_head pointer - list head
*/ void plist_requeue(struct plist_node *node, struct plist_head *head)
{ struct plist_node *iter; struct list_head *node_next = &head->node_list;
/* * After plist_del(), iter is the replacement of the node. If the node * was on prio_list, take shortcut to find node_next instead of looping.
*/ if (!list_empty(&iter->prio_list)) {
iter = list_entry(iter->prio_list.next, struct plist_node,
prio_list);
node_next = &iter->node_list; goto queue;
}
if (node != plist_last(&test_head))
BUG_ON(node->prio == plist_next(node)->prio);
}
staticint __init plist_test(void)
{ int nr_expect = 0, i, loop; unsignedint r = local_clock();
printk(KERN_DEBUG "start plist test\n");
plist_head_init(&test_head); for (i = 0; i < ARRAY_SIZE(test_node); i++)
plist_node_init(test_node + i, 0);
for (loop = 0; loop < 1000; loop++) {
r = r * 193939 % 47629;
i = r % ARRAY_SIZE(test_node); if (plist_node_empty(test_node + i)) {
r = r * 193939 % 47629;
test_node[i].prio = r % 99;
plist_add(test_node + i, &test_head);
nr_expect++;
} else {
plist_del(test_node + i, &test_head);
nr_expect--;
}
plist_test_check(nr_expect); if (!plist_node_empty(test_node + i)) {
plist_test_requeue(test_node + i);
plist_test_check(nr_expect);
}
}
for (i = 0; i < ARRAY_SIZE(test_node); i++) { if (plist_node_empty(test_node + i)) continue;
plist_del(test_node + i, &test_head);
nr_expect--;
plist_test_check(nr_expect);
}
printk(KERN_DEBUG "end plist test\n");
/* Worst case test for plist_add() */ unsignedint test_data[241];
for (i = 0; i < ARRAY_SIZE(test_data); i++)
test_data[i] = i;
ktime_t start, end, time_elapsed = 0;
plist_head_init(&test_head);
for (i = 0; i < ARRAY_SIZE(test_node); i++) {
plist_node_init(test_node + i, 0);
test_node[i].prio = test_data[i];
}
for (i = 0; i < ARRAY_SIZE(test_node); i++) { if (plist_node_empty(test_node + i)) {
start = ktime_get();
plist_add(test_node + i, &test_head);
end = ktime_get();
time_elapsed += (end - start);
}
}
pr_debug("plist_add worst case test time elapsed %lld\n", time_elapsed); return 0;
}
module_init(plist_test);
#endif
Messung V0.5
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.