From: David Woodhouse <dwmw2@infradead.org>
To: Fenghua Yu <fenghua.yu@intel.com>
Cc: Ingo Molnar <mingo@elte.hu>,
Suresh Siddha <suresh.b.siddha@intel.com>,
Andrew Lutomirski <amluto@gmail.com>,
Jesse Barnes <jbarnes@virtuousgeek.org>,
Kyle McMartin <kyle@redhat.com>, Yinghai Lu <yinghai@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
IOMMU <iommu@lists.linux-foundation.org>
Subject: Re: [patch 4/4] Intel IOMMU Suspend/Resume Support - Code Clean Up
Date: Fri, 03 Apr 2009 13:37:17 +0100 [thread overview]
Message-ID: <1238762237.3494.13.camel@macbook.infradead.org> (raw)
In-Reply-To: <20090327212321.520992000@intel.com>>
On Fri, 2009-03-27 at 14:22 -0700, Fenghua Yu wrote:
> plain text document attachment (iommu_sr_4.patch)
> A new macro list_for_each_entry_selected_do() is defined for linked list.
> iommu uses this macro to have concise and more readable code.
>
> It's defined as generic code. Hopefully it could be used in other places.
>
> Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
This is overkill, surely? It would be easier to do...
#define for_each_active_iommu(i, drhd) \
list_for_each_entry(drhd, &dmar_drhd_units, list) \
if (i=drhd->iommu, !drhd->ignored)
#define for_each_iommu(i, drhd) \
list_for_each_entry(drhd, &dmar_drhd_units, list) \
if (i=drhd->iommu, 1)
Or if you really want to avoid it eating a stray 'else' then
#define for_each_active_iommu(i, drhd) \
list_for_each_entry(drhd, &dmar_drhd_units, list) \
if (i=drhd->iommu, drhd->ignored) {} else
#define for_each_iommu(i, drhd) \
list_for_each_entry(drhd, &dmar_drhd_units, list) \
if (i=drhd->iommu, 0) {} else
> ---
>
> include/linux/dmar.h | 8 ++++++++
> include/linux/list.h | 42 ++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 50 insertions(+)
>
> diff --git a/include/linux/dmar.h b/include/linux/dmar.h
> index 2f34274..146d54b 100644
> --- a/include/linux/dmar.h
> +++ b/include/linux/dmar.h
> @@ -44,6 +44,14 @@ extern struct list_head dmar_drhd_units;
> #define for_each_drhd_unit(drhd) \
> list_for_each_entry(drhd, &dmar_drhd_units, list)
>
> +#define for_each_active_iommu(i, drhd) \
> + list_for_each_entry_selected_do(drhd, &dmar_drhd_units, list, \
> + !drhd->ignored, {i = drhd->iommu; })
> +
> +#define for_each_iommu(i, drhd) \
> + list_for_each_entry_selected_do(drhd, &dmar_drhd_units, list, \
> + 1, {i = drhd->iommu; })
> +
> extern int dmar_table_init(void);
> extern int dmar_dev_scope_init(void);
>
> diff --git a/include/linux/list.h b/include/linux/list.h
> index 969f6e9..6580f43 100644
> --- a/include/linux/list.h
> +++ b/include/linux/list.h
> @@ -530,6 +530,48 @@ static inline void list_splice_tail_init(struct list_head *list,
> &pos->member != (head); \
> pos = n, n = list_entry(n->member.prev, typeof(*n), member))
>
> +/**
> + * list_first_entry_selected - get the first selected element from a list
> + * @pos: the type * to use as a loop cursor.
> + * @head: the head for your list.
> + * @member: the name of the list_struct within the struct.
> + * @selector: the selector to select the first entry.
> + */
> +#define list_first_entry_selected(pos, head, member, selector) \
> + pos = list_entry((head)->next, typeof(*pos), member), \
> + pos = ({while (!(selector) && (&pos->member != (head))) \
> + pos = list_entry(pos->member.next, typeof(*pos), member); \
> + pos; })
> +
> +/**
> + * list_next_entry_selected - get the next selected element from a list
> + * @pos: the type * to use as a loop cursor.
> + * @head: the head for your list.
> + * @member: the name of the list_struct within the struct.
> + * @selector: the selector to select the next entry.
> + */
> +#define list_next_entry_selected(pos, head, member, selector) \
> + pos = list_entry(pos->member.next, typeof(*pos), member), \
> + pos = ({while (!(selector) && (&pos->member != (head))) \
> + pos = list_entry(pos->member.next, typeof(*pos), member); \
> + pos; })
> +
> +/**
> + * list_for_each_entry_selected_do - iterate over list of given type and
> + * selected entries. Do something on each selected entry.
> + * @pos: the type * to use as a loop cursor.
> + * @head: the head for your list.
> + * @member: the name of the list_struct within the struct.
> + * @selector: the selector to select entries.
> + * @to_do: things to do on each selected entry.
> + */
> +#define list_for_each_entry_selected_do(pos, head, member, selector, to_do) \
> + for (list_first_entry_selected(pos, head, member, selector), \
> + ({if (&pos->member != (head)) to_do}); \
> + prefetch(pos->member.next), &pos->member != (head); \
> + list_next_entry_selected(pos, head, member, selector), \
> + ({if (&pos->member != (head)) to_do}))
> +
> /*
> * Double linked lists with a single pointer list head.
> * Mostly useful for hash tables where the two pointer list head is
>
--
dwmw2
next prev parent reply other threads:[~2009-04-03 12:37 UTC|newest]
Thread overview: 61+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20090327212241.234500000@intel.com>
2009-03-28 14:24 ` [patch 0/4] Intel IOMMU Supspend/Resume Support Andrew Lutomirski
2009-03-30 23:01 ` David Woodhouse
[not found] ` <20090327212321.520992000@intel.com>
2009-04-03 12:37 ` David Woodhouse [this message]
[not found] ` <20090327212321.070229000@intel.com>
2009-04-16 0:19 ` [PATCH] Intel IOMMU Pass Through Support Fenghua Yu
2009-04-16 2:13 ` Han, Weidong
2009-04-19 10:05 ` David Woodhouse
2009-04-20 17:27 ` Yu, Fenghua
2009-05-13 23:13 ` [PATCH] Fix Intel IOMMU Compilation Warnings on IA64 Fenghua Yu
2009-05-14 15:17 ` David Woodhouse
2009-05-14 15:31 ` Matthew Wilcox
2009-05-14 17:59 ` Fenghua Yu
2009-06-18 18:05 ` [PATCH 1/2] IOMMU Identity Mapping Support: iommu_identity_mapping definition Fenghua Yu
2009-06-18 18:08 ` Muli Ben-Yehuda
2009-06-18 18:13 ` Chris Wright
2009-06-18 18:14 ` Yu, Fenghua
2009-06-18 18:25 ` Muli Ben-Yehuda
2009-06-18 18:31 ` Chris Wright
2009-06-18 18:41 ` Muli Ben-Yehuda
2009-06-18 18:50 ` Yu, Fenghua
2009-06-18 18:51 ` Chris Wright
2009-06-18 19:09 ` Yu, Fenghua
2009-06-25 0:38 ` [PATCH] IA64 Compilation Error Fix for Intel IOMMU Identity Mapping Support Fenghua Yu
2009-06-25 1:00 ` FUJITA Tomonori
2009-06-25 4:16 ` [PATCH v2] " Fenghua Yu
2009-06-25 4:48 ` FUJITA Tomonori
2009-06-25 7:11 ` David Woodhouse
2009-06-25 21:52 ` David Woodhouse
2009-06-25 21:56 ` Yu, Fenghua
2009-06-26 18:21 ` David Woodhouse
2009-06-25 22:00 ` Linus Torvalds
2009-06-25 22:46 ` Tony Luck
2009-06-25 23:43 ` Chris Wright
2009-06-26 1:35 ` Linus Torvalds
2009-06-26 1:52 ` Chris Wright
2009-06-26 2:00 ` Linus Torvalds
2009-06-26 2:08 ` Chris Wright
2009-06-26 11:15 ` David Woodhouse
2009-06-27 0:03 ` Chris Wright
2009-06-27 11:44 ` David Woodhouse
2009-06-18 18:13 ` [PATCH 1/2] IOMMU Identity Mapping Support: iommu_identity_mapping definition Chris Wright
2009-06-18 18:28 ` Yu, Fenghua
2009-06-18 18:34 ` Chris Wright
2009-07-04 18:40 ` David Woodhouse
2009-05-20 17:42 ` [PATCH] Time out for possible dead loops during queued invalidation wait Fenghua Yu
2009-05-27 5:51 ` Andrew Morton
2009-05-27 22:40 ` Yu, Fenghua
2009-05-27 22:48 ` Andrew Morton
2009-05-27 23:25 ` Yu, Fenghua
2009-05-27 23:51 ` Andrew Morton
2009-05-28 0:47 ` Yu, Fenghua
2009-06-18 18:05 ` [PATCH 2/2] IOMMU Identity Mapping Support: Intel IOMMU implementation Fenghua Yu
2009-06-18 19:15 ` Chris Wright
2009-06-18 19:40 ` Yu, Fenghua
2009-06-18 20:02 ` Chris Wright
2009-06-19 20:47 ` [PATCH v2] IOMMU Identity Mapping Support (drivers/pci/intel_iommu.c) Fenghua Yu
2009-04-30 23:29 ` [PATCH] Intel IOMMU Pass Through Support Andrew Morton
2009-04-30 23:37 ` Randy Dunlap
2009-05-01 0:00 ` Andrew Morton
2009-05-01 0:57 ` Fenghua Yu
2009-05-01 0:05 ` Fenghua Yu
2009-05-01 0:14 ` Andrew Morton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1238762237.3494.13.camel@macbook.infradead.org \
--to=dwmw2@infradead.org \
--cc=amluto@gmail.com \
--cc=fenghua.yu@intel.com \
--cc=iommu@lists.linux-foundation.org \
--cc=jbarnes@virtuousgeek.org \
--cc=kyle@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=suresh.b.siddha@intel.com \
--cc=yinghai@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®