summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorRasmus Villemoes <rasmus.villemoes@prevas.dk>2022-10-28 14:50:53 +0300
committerStefan Roese <sr@denx.de>2022-11-02 10:41:55 +0300
commit28968394839bec37dacf6ffc2ae880e38756e917 (patch)
tree8dfb3538a21379a017537937e071c8beb7284b2d /cmd
parent2399b628f4c1c92bbe9033273b450b1e514f802e (diff)
downloadu-boot-28968394839bec37dacf6ffc2ae880e38756e917.tar.xz
cyclic: switch to using hlist instead of list
A hlist is headed by just a single pointer, so can only be traversed forwards, and insertions can only happen at the head (or before/after an existing list member). But each list node still consists of two pointers, so arbitrary elements can still be removed in O(1). This is precisely what we need for the cyclic_list - we never need to traverse it backwards, and the order the callbacks appear in the list should really not matter. One advantage, and the main reason for doing this switch, is that an empty list is represented by a NULL head pointer, so unlike a list_head, it does not need separate C code to initialize - a memset(,0,) of the containing structure is sufficient. This is mostly mechanical: - The iterators are updated with an h prefix, and the type of the temporary variable changed to struct hlist_node*. - Adding/removing is now just hlist_add_head (and not tail) and hlist_del(). - struct members and function return values updated. Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk> Reviewed-by: Stefan Roese <sr@denx.de> Tested-by: Stefan Roese <sr@denx.de> Tested-by: Tim Harvey <tharvey@gateworks.com> # imx8mm-venice-*
Diffstat (limited to 'cmd')
-rw-r--r--cmd/cyclic.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/cmd/cyclic.c b/cmd/cyclic.c
index c1bc556aad..97324d8240 100644
--- a/cmd/cyclic.c
+++ b/cmd/cyclic.c
@@ -61,10 +61,11 @@ static int do_cyclic_demo(struct cmd_tbl *cmdtp, int flag, int argc,
static int do_cyclic_list(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
- struct cyclic_info *cyclic, *tmp;
+ struct cyclic_info *cyclic;
+ struct hlist_node *tmp;
u64 cnt, freq;
- list_for_each_entry_safe(cyclic, tmp, cyclic_get_list(), list) {
+ hlist_for_each_entry_safe(cyclic, tmp, cyclic_get_list(), list) {
cnt = cyclic->run_cnt * 1000000ULL * 100ULL;
freq = lldiv(cnt, timer_get_us() - cyclic->start_time_us);
printf("function: %s, cpu-time: %lld us, frequency: %lld.%02d times/s\n",