Skip to contentSkip to conversation

list.h minor clean

PATCH In review Rusty Russell 2 participants 2 messages Jan 25, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 list.h minor clean

Hi all,

When I added (the typesafe) list_for_each_entry() to Linux's list.h I
considered just calling it list_for_each(), and replacing all the callers, but the size of the task defeated me. Xen, however, is smaller.

You may think this patch sucks, but I had to try. Boot tested.

Rusty.
PS. I haven't seen a discussion on codingstyle: some of these are definitely not Linux-style...

xen/arch/x86/domain.c +1 -3
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal xen-unstable-base/xen/arch/x86/domain.c xen-unstable/xen/arch/x86/domain.c
@@ -206,13 +206,11 @@ void machine_halt(void)
 void dump_pageframe_info(struct domain *d)
 {
     struct pfn_info *page;
-    struct list_head *ent;
 
     if ( d->tot_pages < 10 )
     {
-        list_for_each ( ent, &d->page_list )
+        list_for_each ( page, &d->page_list, list )
         {
-            page = list_entry(ent, struct pfn_info, list);
             printk("Page %08x: caf=%08x, taf=%08x\n",
                    page_to_phys(page), page->count_info,
                    page->u.inuse.type_info);
xen/arch/x86/mpparse.c +1 -4
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal xen-unstable-base/xen/arch/x86/mpparse.c xen-unstable/xen/arch/x86/mpparse.c
@@ -1232,7 +1232,6 @@ void __init mp_config_acpi_legacy_irqs (
 
 void __init mp_parse_prt (void)
 {
-	struct list_head	*node = NULL;
 	struct acpi_prt_entry	*entry = NULL;
 	int			ioapic = -1;
 	int			ioapic_pin = 0;
@@ -1245,9 +1244,7 @@ void __init mp_parse_prt (void)
 	 * Parsing through the PCI Interrupt Routing Table (PRT) and program
 	 * routing for all entries.
 	 */
-	list_for_each(node, &acpi_prt.entries) {
-		entry = list_entry(node, struct acpi_prt_entry, node);
-
+	list_for_each(entry, &acpi_prt.entries, node) {
 		/* Need to get irq for dynamic entry */
 		if (entry->link.handle) {
 			irq = acpi_pci_link_get_irq(entry->link.handle, entry->link.index, &edge_level, &active_high_low);
xen/arch/x86/pci-pc.c +1 -3
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal xen-unstable-base/xen/arch/x86/pci-pc.c xen-unstable/xen/arch/x86/pci-pc.c
@@ -1372,11 +1372,9 @@ void __devinit  pcibios_fixup_bus(struct
 
 struct pci_bus * __devinit pcibios_scan_root(int busnum)
 {
-	struct list_head *list;
 	struct pci_bus *bus;
 
-	list_for_each(list, &pci_root_buses) {
-		bus = pci_bus_b(list);
+	pci_for_each_bus(bus) {
 		if (bus->number == busnum) {
 			/* Already scanned */
 			return bus;
xen/arch/x86/pdb-stub.c +2 -6
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal xen-unstable-base/xen/arch/x86/pdb-stub.c xen-unstable/xen/arch/x86/pdb-stub.c
@@ -778,12 +778,10 @@ void pdb_bkpt_add (unsigned long cr3, un
 struct pdb_breakpoint* pdb_bkpt_search (unsigned long cr3, 
 					unsigned long address)
 {
-    struct list_head *list_entry;
     struct pdb_breakpoint *bkpt;
 
-    list_for_each(list_entry, &breakpoints.list)
+    list_for_each(bkpt, &breakpoints.list, list)
     {
-        bkpt = list_entry(list_entry, struct pdb_breakpoint, list);
 	if ( bkpt->cr3 == cr3 && bkpt->address == address )
             return bkpt;
     }
@@ -798,11 +796,9 @@ struct pdb_breakpoint* pdb_bkpt_search (
 int pdb_bkpt_remove (unsigned long cr3, unsigned long address)
 {
     struct list_head *list_entry;
-    struct pdb_breakpoint *bkpt;
 
-    list_for_each(list_entry, &breakpoints.list)
+    list_for_each(bkpt, &breakpoints.list, list)
     {
-        bkpt = list_entry(list_entry, struct pdb_breakpoint, list);
 	if ( bkpt->cr3 == cr3 && bkpt->address == address )
 	{
             list_del(&bkpt->list);
xen/common/physdev.c +4 -9
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal xen-unstable-base/xen/common/physdev.c xen-unstable/xen/common/physdev.c
@@ -73,11 +73,9 @@ typedef struct _phys_dev_st {
 static phys_dev_t *find_pdev(struct domain *p, struct pci_dev *dev)
 {
     phys_dev_t *t, *res = NULL;
-    struct list_head *tmp;
 
-    list_for_each(tmp, &p->pcidev_list)
+    list_for_each(t, &p->pcidev_list, node)
     {
-        t = list_entry(tmp,  phys_dev_t, node);
         if ( dev == t->dev )
         {
             res = t;
@@ -230,17 +228,16 @@ int physdev_pci_access_modify(
 int domain_iomem_in_pfn(struct domain *p, unsigned long pfn)
 {
     int ret = 0;
-    struct list_head *l;
+	phys_dev_t *phys_dev;
 
     VERBOSE_INFO("Checking if physdev-capable domain %u needs access to "
                  "pfn %08lx\n", p->id, pfn);
     
     spin_lock(&p->pcidev_lock);
 
-    list_for_each(l, &p->pcidev_list)
+    list_for_each(phys_dev, &p->pcidev_list, node)
     {
         int i;
-        phys_dev_t *phys_dev = list_entry(l, phys_dev_t, node);
         struct pci_dev *pci_dev = phys_dev->dev;
 
         for ( i = 0; (i < DEVICE_COUNT_RESOURCE) && (ret == 0); i++ )
@@ -635,13 +632,11 @@ static long pci_cfgreg_write(int bus, in
 static long pci_probe_root_buses(u32 *busmask)
 {
     phys_dev_t *pdev;
-    struct list_head *tmp;
 
     memset(busmask, 0, 256/8);
 
-    list_for_each ( tmp, &current->domain->pcidev_list )
+    list_for_each ( pdev, &current->domain->pcidev_list, node )
     {
-        pdev = list_entry(tmp, phys_dev_t, node);
         set_bit(pdev->dev->bus->number, busmask);
     }
 
xen/common/sched_atropos.c +23 -35

153 lines not on this page · raw message

xen/common/sched_bvt.c +6 -9
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal xen-unstable-base/xen/common/sched_bvt.c xen-unstable/xen/common/sched_bvt.c
@@ -370,7 +370,6 @@ static task_slice_t bvt_do_schedule(s_ti
 {
     struct domain *d;
     struct exec_domain      *prev = current, *next = NULL, *next_prime, *ed; 
-    struct list_head   *tmp;
     int                 cpu = prev->processor;
     s32                 r_time;     /* time for new dom to run */
     u32                 next_evt, next_prime_evt, min_avt;
@@ -415,10 +414,8 @@ static task_slice_t bvt_do_schedule(s_ti
     next_prime_evt = ~0U;
     min_avt        = ~0U;
 
-    list_for_each ( tmp, RUNQUEUE(cpu) )
+    list_for_each ( p_einf, RUNQUEUE(cpu), run_list )
     {
-        p_einf = list_entry(tmp, struct bvt_edom_info, run_list);
-
         if ( p_einf->evt < next_evt )
         {
             next_prime_einf  = next_einf;
@@ -530,7 +527,7 @@ static void bvt_dump_settings(void)
 
 static void bvt_dump_cpu_state(int i)
 {
-    struct list_head *list, *queue;
+    struct list_head *queue;
     int loop = 0;
     struct bvt_edom_info *d_inf;
     struct exec_domain *d;
@@ -541,17 +538,17 @@ static void bvt_dump_cpu_state(int i)
     printk("QUEUE rq %lx   n: %lx, p: %lx\n",  (unsigned long)queue,
            (unsigned long) queue->next, (unsigned long) queue->prev);
 
-    list_for_each ( list, queue )
+    list_for_each ( d_inf, queue, run_list )
     {
-        d_inf = list_entry(list, struct bvt_edom_info, run_list);
         d = d_inf->exec_domain;
         printk("%3d: %u has=%c ", loop++, d->domain->id,
                test_bit(EDF_RUNNING, &d->ed_flags) ? 'T':'F');
         bvt_dump_runq_el(d);
         printk("c=0x%X%08X\n", (u32)(d->cpu_time>>32), (u32)d->cpu_time);
         printk("         l: %lx n: %lx  p: %lx\n",
-               (unsigned long)list, (unsigned long)list->next,
-               (unsigned long)list->prev);
+               (unsigned long)&d_inf->run_list,
+			   (unsigned long)d_inf->run_list.next,
+               (unsigned long)d_inf->run_list.prev);
     }
 }
 
xen/common/sched_rrobin.c +2 -3
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal xen-unstable-base/xen/common/sched_rrobin.c xen-unstable/xen/common/sched_rrobin.c
@@ -187,7 +187,7 @@ static void rr_dump_domain(struct domain
 
 static void rr_dump_cpu_state(int i)
 {
-    struct list_head *list, *queue;
+    struct list_head *queue;
     int loop = 0;
     struct rrobin_dom_info *d_inf;
 
@@ -199,10 +199,9 @@ static void rr_dump_cpu_state(int i)
     d_inf = list_entry(queue, struct rrobin_dom_info, run_list);
     rr_dump_domain(d_inf->domain);
  
-    list_for_each ( list, queue )
+    list_for_each ( d_inf, queue, run_list )
     {
         printk("%3d: ",loop++);
-        d_inf = list_entry(list, struct rrobin_dom_info, run_list);
         rr_dump_domain(d_inf->domain);
     }
 }
xen/common/slab.c +8 -14
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal xen-unstable-base/xen/common/slab.c xen-unstable/xen/common/slab.c
@@ -774,11 +774,9 @@ xmem_cache_create (const char *name, siz
     /* Need the semaphore to access the chain. */
     down(&cache_chain_sem);
     {
-        struct list_head *p;
-
-        list_for_each(p, &cache_chain) {
-            xmem_cache_t *pc = list_entry(p, xmem_cache_t, next);
+	xmem_cache_t *pc;
 
+        list_for_each(pc, &cache_chain, next) {
             /* The name field is constant - no lock needed. */
             if (!strcmp(pc->name, name))
                 BUG();
@@ -802,14 +800,14 @@ xmem_cache_create (const char *name, siz
  */
 static int is_chained_xmem_cache(xmem_cache_t * cachep)
 {
-    struct list_head *p;
+    xmem_cache_t *pc;
     int ret = 0;
     unsigned long spin_flags;
 
     /* Find the cache in the chain of caches. */
     down(&cache_chain_sem);
-    list_for_each(p, &cache_chain) {
-        if (p == &cachep->next) {
+    list_for_each(pc, &cache_chain, next) {
+        if (pc == &cachep) {
             ret = 1;
             break;
         }
@@ -1765,7 +1763,6 @@ void dump_slabinfo()
     p = &cache_cache.next;
     do {
         xmem_cache_t	*cachep;
-        struct list_head *q;
         slab_t		*slabp;
         unsigned long	active_objs;
         unsigned long	num_objs;
@@ -1776,22 +1773,19 @@ void dump_slabinfo()
         spin_lock_irq(&cachep->spinlock);
         active_objs = 0;
         num_slabs = 0;
-        list_for_each(q,&cachep->slabs_full) {
-            slabp = list_entry(q, slab_t, list);
+        list_for_each(slabp, &cachep->slabs_full, list) {
             if (slabp->inuse != cachep->num)
                 BUG();
             active_objs += cachep->num;
             active_slabs++;
         }
-        list_for_each(q,&cachep->slabs_partial) {
-            slabp = list_entry(q, slab_t, list);
+        list_for_each(slabp, &cachep->slabs_partial, list) {
             if (slabp->inuse == cachep->num || !slabp->inuse)
                 BUG();
             active_objs += slabp->inuse;
             active_slabs++;
         }
-        list_for_each(q,&cachep->slabs_free) {
-            slabp = list_entry(q, slab_t, list);
+        list_for_each(slabp, &cachep->slabs_free, list) {
             if (slabp->inuse)
                 BUG();
             num_slabs++;
xen/drivers/pci/pci.c +18 -24

95 lines not on this page · raw message

xen/include/xen/list.h +13 -21
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal xen-unstable-base/xen/include/xen/list.h xen-unstable/xen/include/xen/list.h
@@ -144,34 +144,26 @@ static __inline__ void list_splice(struc
 	((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
 
 /**
- * list_for_each	-	iterate over a list
- * @pos:	the &struct list_head to use as a loop counter.
- * @head:	the head for your list.
- */
-#define list_for_each(pos, head) \
-	for (pos = (head)->next; pos != (head); pos = pos->next)
-        	
-/**
- * list_for_each_safe	-	iterate over a list safe against removal of list entry
- * @pos:	the &struct list_head to use as a loop counter.
- * @n:		another &struct list_head to use as temporary storage
+ * list_for_each	-	iterate over list of given type
+ * @pos:	the type * to use as a loop counter.
  * @head:	the head for your list.
+ * @member:	the name of the list_struct within the struct.
  */
-#define list_for_each_safe(pos, n, head) \
-	for (pos = (head)->next, n = pos->next; pos != (head); \
-		pos = n, n = pos->next)
-
-#endif
+#define list_for_each(pos, head, member)				\
+	for (pos = list_entry((head)->next, typeof(*pos), member);	\
+	     &pos->member != (head); 					\
+	     pos = list_entry(pos->member.next, typeof(*pos), member))
 
 /**
- * list_for_each_entry	-	iterate over list of given type
+ * list_for_each_safe - iterate over list of given type safe against removal of list entry
  * @pos:	the type * to use as a loop counter.
+ * @n:		another type * to use as temporary storage
  * @head:	the head for your list.
  * @member:	the name of the list_struct within the struct.
  */
-#define list_for_each_entry(pos, head, member)				\
+#define list_for_each_safe(pos, n, head, member)			\
 	for (pos = list_entry((head)->next, typeof(*pos), member),	\
-		     prefetch(pos->member.next);			\
+		n = list_entry(pos->member.next, typeof(*pos), member);	\
 	     &pos->member != (head); 					\
-	     pos = list_entry(pos->member.next, typeof(*pos), member),	\
-		     prefetch(pos->member.next))
+	     pos = n, n = list_entry(n->member.next, typeof(*n), member))
+#endif
xen/include/xen/pci.h +1 -1
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal xen-unstable-base/xen/include/xen/pci.h xen-unstable/xen/include/xen/pci.h
@@ -358,7 +358,7 @@ enum pci_mmap_state {
 	for(dev = pci_dev_g(pci_devices.prev); dev != pci_dev_g(&pci_devices); dev = pci_dev_g(dev->global_list.prev))
 
 #define pci_for_each_bus(bus) \
-for(bus = pci_bus_b(pci_root_buses.next); bus != pci_bus_b(&pci_root_buses); bus = pci_bus_b(bus->node.next))
+	list_for_each(bus, &pci_root_buses, node)
 
 /*
  * The pci_dev structure is used to describe both PCI and ISAPnP devices.
Signature · 9 lines
A bad analogy is like a leaky screwdriver -- Richard Braakman



-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl
#1 lore raw
Quoted 8 lines

Hi all,

When I added (the typesafe) list_for_each_entry() to Linux's list.h I
considered just calling it list_for_each(), and replacing all the callers, but the size of the task defeated me. Xen, however, is smaller.

You may think this patch sucks, but I had to try. Boot tested.

I like it. I've always disliked the Linux use of list_entry() to get the containing structure. I'll read through it a bit more carefully and then check it in. Thanks!

I may keep the rename though -- some other arch developers want to pull in or symlink to unmodified Linux source files, and they won;t appreciate the name clash. :-)

Quoted 3 lines

Rusty.
PS. I haven't seen a discussion on codingstyle: some of these are definitely not Linux-style...

I hate that the Linux style uses 8-space hard tabs. I could live with it apart from that.

-- Keir

-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting Tool for open source databases. Create drag-&-drop reports. Save time by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc. Download a FREE copy at http://www.intelliview.com/go/osdn_nl