* [PATCH] gnttab: cleanup of number-of-active-frames calculations
@ 2012-09-11 11:58 Jan Beulich
2012-09-11 13:34 ` Keir Fraser
0 siblings, 1 reply; 2+ messages in thread
From: Jan Beulich @ 2012-09-11 11:58 UTC (permalink / raw)
To: xen-devel
[-- Attachment #1: Type: text/plain, Size: 5268 bytes --]
max_nr_active_grant_frames() is merly is special case of
num_act_frames_from_sha_frames(), so there's no need to have a special
case implementation for it.
Further, some of the related definitions (including the "struct
active_grant_entry" definition itself) can (and hence should) really be
private to grant_table.c.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
--- a/xen/common/grant_table.c
+++ b/xen/common/grant_table.c
@@ -127,10 +127,45 @@ shared_entry_header(struct grant_table *
else
return &shared_entry_v2(t, ref).hdr;
}
+
+/* Active grant entry - used for shadowing GTF_permit_access grants. */
+struct active_grant_entry {
+ u32 pin; /* Reference count information. */
+ domid_t domid; /* Domain being granted access. */
+ struct domain *trans_domain;
+ uint32_t trans_gref;
+ unsigned long frame; /* Frame being granted. */
+ unsigned long gfn; /* Guest's idea of the frame being granted. */
+ unsigned is_sub_page:1; /* True if this is a sub-page grant. */
+ unsigned start:15; /* For sub-page grants, the start offset
+ in the page. */
+ unsigned length:16; /* For sub-page grants, the length of the
+ grant. */
+};
+
#define ACGNT_PER_PAGE (PAGE_SIZE / sizeof(struct active_grant_entry))
#define active_entry(t, e) \
((t)->active[(e)/ACGNT_PER_PAGE][(e)%ACGNT_PER_PAGE])
+static inline unsigned int
+num_act_frames_from_sha_frames(const unsigned int num)
+{
+ /* How many frames are needed for the active grant table,
+ * given the size of the shared grant table? */
+ unsigned int sha_per_page = PAGE_SIZE / sizeof(grant_entry_v1_t);
+ unsigned int num_sha_entries = num * sha_per_page;
+ return (num_sha_entries + (ACGNT_PER_PAGE - 1)) / ACGNT_PER_PAGE;
+}
+
+#define max_nr_active_grant_frames \
+ num_act_frames_from_sha_frames(max_nr_grant_frames)
+
+static inline unsigned int
+nr_active_grant_frames(struct grant_table *gt)
+{
+ return num_act_frames_from_sha_frames(nr_grant_frames(gt));
+}
+
/* Check if the page has been paged out, or needs unsharing.
If rc == GNTST_okay, *page contains the page struct with a ref taken.
Caller must do put_page(*page).
@@ -2542,13 +2577,6 @@ do_grant_table_op(
#include "compat/grant_table.c"
#endif
-static unsigned int max_nr_active_grant_frames(void)
-{
- return (((max_nr_grant_frames * (PAGE_SIZE / sizeof(grant_entry_v1_t))) +
- ((PAGE_SIZE / sizeof(struct active_grant_entry))-1))
- / (PAGE_SIZE / sizeof(struct active_grant_entry)));
-}
-
int
grant_table_create(
struct domain *d)
@@ -2565,7 +2593,7 @@ grant_table_create(
/* Active grant table. */
if ( (t->active = xzalloc_array(struct active_grant_entry *,
- max_nr_active_grant_frames())) == NULL )
+ max_nr_active_grant_frames)) == NULL )
goto no_mem_1;
for ( i = 0;
i < num_act_frames_from_sha_frames(INITIAL_NR_GRANT_FRAMES); i++ )
--- a/xen/include/xen/grant_table.h
+++ b/xen/include/xen/grant_table.h
@@ -28,21 +28,6 @@
#include <asm/page.h>
#include <asm/grant_table.h>
-/* Active grant entry - used for shadowing GTF_permit_access grants. */
-struct active_grant_entry {
- u32 pin; /* Reference count information. */
- domid_t domid; /* Domain being granted access. */
- struct domain *trans_domain;
- uint32_t trans_gref;
- unsigned long frame; /* Frame being granted. */
- unsigned long gfn; /* Guest's idea of the frame being granted. */
- unsigned is_sub_page:1; /* True if this is a sub-page grant. */
- unsigned start:15; /* For sub-page grants, the start offset
- in the page. */
- unsigned length:16; /* For sub-page grants, the length of the
- grant. */
-};
-
/* Count of writable host-CPU mappings. */
#define GNTPIN_hstw_shift (0)
#define GNTPIN_hstw_inc (1 << GNTPIN_hstw_shift)
@@ -147,23 +132,4 @@ static inline unsigned int grant_to_stat
GRANT_STATUS_PER_PAGE;
}
-static inline unsigned int
-num_act_frames_from_sha_frames(const unsigned int num)
-{
- /* How many frames are needed for the active grant table,
- * given the size of the shared grant table? */
- unsigned act_per_page = PAGE_SIZE / sizeof(struct active_grant_entry);
- unsigned sha_per_page = PAGE_SIZE / sizeof(grant_entry_v1_t);
- unsigned num_sha_entries = num * sha_per_page;
- unsigned num_act_frames =
- (num_sha_entries + (act_per_page-1)) / act_per_page;
- return num_act_frames;
-}
-
-static inline unsigned int
-nr_active_grant_frames(struct grant_table *gt)
-{
- return num_act_frames_from_sha_frames(nr_grant_frames(gt));
-}
-
#endif /* __XEN_GRANT_TABLE_H__ */
[-- Attachment #2: gnttab-max-nr-active.patch --]
[-- Type: text/plain, Size: 5323 bytes --]
gnttab: cleanup of number-of-active-frames calculations
max_nr_active_grant_frames() is merly is special case of
num_act_frames_from_sha_frames(), so there's no need to have a special
case implementation for it.
Further, some of the related definitions (including the "struct
active_grant_entry" definition itself) can (and hence should) really be
private to grant_table.c.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
--- a/xen/common/grant_table.c
+++ b/xen/common/grant_table.c
@@ -127,10 +127,45 @@ shared_entry_header(struct grant_table *
else
return &shared_entry_v2(t, ref).hdr;
}
+
+/* Active grant entry - used for shadowing GTF_permit_access grants. */
+struct active_grant_entry {
+ u32 pin; /* Reference count information. */
+ domid_t domid; /* Domain being granted access. */
+ struct domain *trans_domain;
+ uint32_t trans_gref;
+ unsigned long frame; /* Frame being granted. */
+ unsigned long gfn; /* Guest's idea of the frame being granted. */
+ unsigned is_sub_page:1; /* True if this is a sub-page grant. */
+ unsigned start:15; /* For sub-page grants, the start offset
+ in the page. */
+ unsigned length:16; /* For sub-page grants, the length of the
+ grant. */
+};
+
#define ACGNT_PER_PAGE (PAGE_SIZE / sizeof(struct active_grant_entry))
#define active_entry(t, e) \
((t)->active[(e)/ACGNT_PER_PAGE][(e)%ACGNT_PER_PAGE])
+static inline unsigned int
+num_act_frames_from_sha_frames(const unsigned int num)
+{
+ /* How many frames are needed for the active grant table,
+ * given the size of the shared grant table? */
+ unsigned int sha_per_page = PAGE_SIZE / sizeof(grant_entry_v1_t);
+ unsigned int num_sha_entries = num * sha_per_page;
+ return (num_sha_entries + (ACGNT_PER_PAGE - 1)) / ACGNT_PER_PAGE;
+}
+
+#define max_nr_active_grant_frames \
+ num_act_frames_from_sha_frames(max_nr_grant_frames)
+
+static inline unsigned int
+nr_active_grant_frames(struct grant_table *gt)
+{
+ return num_act_frames_from_sha_frames(nr_grant_frames(gt));
+}
+
/* Check if the page has been paged out, or needs unsharing.
If rc == GNTST_okay, *page contains the page struct with a ref taken.
Caller must do put_page(*page).
@@ -2542,13 +2577,6 @@ do_grant_table_op(
#include "compat/grant_table.c"
#endif
-static unsigned int max_nr_active_grant_frames(void)
-{
- return (((max_nr_grant_frames * (PAGE_SIZE / sizeof(grant_entry_v1_t))) +
- ((PAGE_SIZE / sizeof(struct active_grant_entry))-1))
- / (PAGE_SIZE / sizeof(struct active_grant_entry)));
-}
-
int
grant_table_create(
struct domain *d)
@@ -2565,7 +2593,7 @@ grant_table_create(
/* Active grant table. */
if ( (t->active = xzalloc_array(struct active_grant_entry *,
- max_nr_active_grant_frames())) == NULL )
+ max_nr_active_grant_frames)) == NULL )
goto no_mem_1;
for ( i = 0;
i < num_act_frames_from_sha_frames(INITIAL_NR_GRANT_FRAMES); i++ )
--- a/xen/include/xen/grant_table.h
+++ b/xen/include/xen/grant_table.h
@@ -28,21 +28,6 @@
#include <asm/page.h>
#include <asm/grant_table.h>
-/* Active grant entry - used for shadowing GTF_permit_access grants. */
-struct active_grant_entry {
- u32 pin; /* Reference count information. */
- domid_t domid; /* Domain being granted access. */
- struct domain *trans_domain;
- uint32_t trans_gref;
- unsigned long frame; /* Frame being granted. */
- unsigned long gfn; /* Guest's idea of the frame being granted. */
- unsigned is_sub_page:1; /* True if this is a sub-page grant. */
- unsigned start:15; /* For sub-page grants, the start offset
- in the page. */
- unsigned length:16; /* For sub-page grants, the length of the
- grant. */
-};
-
/* Count of writable host-CPU mappings. */
#define GNTPIN_hstw_shift (0)
#define GNTPIN_hstw_inc (1 << GNTPIN_hstw_shift)
@@ -147,23 +132,4 @@ static inline unsigned int grant_to_stat
GRANT_STATUS_PER_PAGE;
}
-static inline unsigned int
-num_act_frames_from_sha_frames(const unsigned int num)
-{
- /* How many frames are needed for the active grant table,
- * given the size of the shared grant table? */
- unsigned act_per_page = PAGE_SIZE / sizeof(struct active_grant_entry);
- unsigned sha_per_page = PAGE_SIZE / sizeof(grant_entry_v1_t);
- unsigned num_sha_entries = num * sha_per_page;
- unsigned num_act_frames =
- (num_sha_entries + (act_per_page-1)) / act_per_page;
- return num_act_frames;
-}
-
-static inline unsigned int
-nr_active_grant_frames(struct grant_table *gt)
-{
- return num_act_frames_from_sha_frames(nr_grant_frames(gt));
-}
-
#endif /* __XEN_GRANT_TABLE_H__ */
[-- Attachment #3: Type: text/plain, Size: 126 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] gnttab: cleanup of number-of-active-frames calculations
2012-09-11 11:58 [PATCH] gnttab: cleanup of number-of-active-frames calculations Jan Beulich
@ 2012-09-11 13:34 ` Keir Fraser
0 siblings, 0 replies; 2+ messages in thread
From: Keir Fraser @ 2012-09-11 13:34 UTC (permalink / raw)
To: Jan Beulich, xen-devel
On 11/09/2012 12:58, "Jan Beulich" <JBeulich@suse.com> wrote:
> max_nr_active_grant_frames() is merly is special case of
> num_act_frames_from_sha_frames(), so there's no need to have a special
> case implementation for it.
>
> Further, some of the related definitions (including the "struct
> active_grant_entry" definition itself) can (and hence should) really be
> private to grant_table.c.
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Keir Fraser <keir@xen.org>
> --- a/xen/common/grant_table.c
> +++ b/xen/common/grant_table.c
> @@ -127,10 +127,45 @@ shared_entry_header(struct grant_table *
> else
> return &shared_entry_v2(t, ref).hdr;
> }
> +
> +/* Active grant entry - used for shadowing GTF_permit_access grants. */
> +struct active_grant_entry {
> + u32 pin; /* Reference count information. */
> + domid_t domid; /* Domain being granted access. */
> + struct domain *trans_domain;
> + uint32_t trans_gref;
> + unsigned long frame; /* Frame being granted. */
> + unsigned long gfn; /* Guest's idea of the frame being granted. */
> + unsigned is_sub_page:1; /* True if this is a sub-page grant. */
> + unsigned start:15; /* For sub-page grants, the start offset
> + in the page. */
> + unsigned length:16; /* For sub-page grants, the length of the
> + grant. */
> +};
> +
> #define ACGNT_PER_PAGE (PAGE_SIZE / sizeof(struct active_grant_entry))
> #define active_entry(t, e) \
> ((t)->active[(e)/ACGNT_PER_PAGE][(e)%ACGNT_PER_PAGE])
>
> +static inline unsigned int
> +num_act_frames_from_sha_frames(const unsigned int num)
> +{
> + /* How many frames are needed for the active grant table,
> + * given the size of the shared grant table? */
> + unsigned int sha_per_page = PAGE_SIZE / sizeof(grant_entry_v1_t);
> + unsigned int num_sha_entries = num * sha_per_page;
> + return (num_sha_entries + (ACGNT_PER_PAGE - 1)) / ACGNT_PER_PAGE;
> +}
> +
> +#define max_nr_active_grant_frames \
> + num_act_frames_from_sha_frames(max_nr_grant_frames)
> +
> +static inline unsigned int
> +nr_active_grant_frames(struct grant_table *gt)
> +{
> + return num_act_frames_from_sha_frames(nr_grant_frames(gt));
> +}
> +
> /* Check if the page has been paged out, or needs unsharing.
> If rc == GNTST_okay, *page contains the page struct with a ref taken.
> Caller must do put_page(*page).
> @@ -2542,13 +2577,6 @@ do_grant_table_op(
> #include "compat/grant_table.c"
> #endif
>
> -static unsigned int max_nr_active_grant_frames(void)
> -{
> - return (((max_nr_grant_frames * (PAGE_SIZE / sizeof(grant_entry_v1_t))) +
> - ((PAGE_SIZE / sizeof(struct active_grant_entry))-1))
> - / (PAGE_SIZE / sizeof(struct active_grant_entry)));
> -}
> -
> int
> grant_table_create(
> struct domain *d)
> @@ -2565,7 +2593,7 @@ grant_table_create(
>
> /* Active grant table. */
> if ( (t->active = xzalloc_array(struct active_grant_entry *,
> - max_nr_active_grant_frames())) == NULL )
> + max_nr_active_grant_frames)) == NULL )
> goto no_mem_1;
> for ( i = 0;
> i < num_act_frames_from_sha_frames(INITIAL_NR_GRANT_FRAMES); i++ )
> --- a/xen/include/xen/grant_table.h
> +++ b/xen/include/xen/grant_table.h
> @@ -28,21 +28,6 @@
> #include <asm/page.h>
> #include <asm/grant_table.h>
>
> -/* Active grant entry - used for shadowing GTF_permit_access grants. */
> -struct active_grant_entry {
> - u32 pin; /* Reference count information. */
> - domid_t domid; /* Domain being granted access. */
> - struct domain *trans_domain;
> - uint32_t trans_gref;
> - unsigned long frame; /* Frame being granted. */
> - unsigned long gfn; /* Guest's idea of the frame being granted. */
> - unsigned is_sub_page:1; /* True if this is a sub-page grant. */
> - unsigned start:15; /* For sub-page grants, the start offset
> - in the page. */
> - unsigned length:16; /* For sub-page grants, the length of the
> - grant. */
> -};
> -
> /* Count of writable host-CPU mappings. */
> #define GNTPIN_hstw_shift (0)
> #define GNTPIN_hstw_inc (1 << GNTPIN_hstw_shift)
> @@ -147,23 +132,4 @@ static inline unsigned int grant_to_stat
> GRANT_STATUS_PER_PAGE;
> }
>
> -static inline unsigned int
> -num_act_frames_from_sha_frames(const unsigned int num)
> -{
> - /* How many frames are needed for the active grant table,
> - * given the size of the shared grant table? */
> - unsigned act_per_page = PAGE_SIZE / sizeof(struct active_grant_entry);
> - unsigned sha_per_page = PAGE_SIZE / sizeof(grant_entry_v1_t);
> - unsigned num_sha_entries = num * sha_per_page;
> - unsigned num_act_frames =
> - (num_sha_entries + (act_per_page-1)) / act_per_page;
> - return num_act_frames;
> -}
> -
> -static inline unsigned int
> -nr_active_grant_frames(struct grant_table *gt)
> -{
> - return num_act_frames_from_sha_frames(nr_grant_frames(gt));
> -}
> -
> #endif /* __XEN_GRANT_TABLE_H__ */
>
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> http://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-09-11 13:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-11 11:58 [PATCH] gnttab: cleanup of number-of-active-frames calculations Jan Beulich
2012-09-11 13:34 ` Keir Fraser
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).