All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jimi Xenidis <jimix@watson.ibm.com>
To: Keir Fraser <keir@xensource.com>
Cc: xen-devel@lists.xensource.com
Subject: Re: [RFC] Re: [PATCH] fix xenctl_cpumap translation to handle bitops accessed like arrays
Date: Tue, 16 Jan 2007 18:26:19 -0500	[thread overview]
Message-ID: <t16k5zmpn8k.fsf@pobox.com> (raw)
In-Reply-To: <C1B09624.6228%keir@xensource.com> (Keir Fraser's message of "Thu, 21 Dec 2006 19:51:00 +0000")

Keir Fraser <keir@xensource.com> writes:

> On 21/12/06 5:32 pm, "Jimi Xenidis" <jimix@watson.ibm.com> wrote:
>
>>> How about functions long_to_byte_bitmap(bitmap, nr_bits) and
>>> byte_to_long_bitmap(bitmap, nr_bits) defined in asm/bitops.h?
>> 
[snip]
>
> The way you are doing the conversion would be fine. I'm mainly aiming for a
> clean abstraction and formalising the concept of a 'byte-oriented bitmap' is
> the best way of doing this that I can see right now.

Sorry for taking so long with this, please comment on the following:

The following patch adds the ability to convert form "long" based
bitmaps to "byte" base bitmaps for portability. This is only has the
hypervisor side, but the definitions are such that the same prototype
can be use by XC and Xen.

Sadly it adds a copy on the xenctl_cpumap_to_cpumask(), but it minimally impacts the common paths.

-JX


diff -r a6813a652f39 xen/arch/powerpc/domctl.c
--- a/xen/arch/powerpc/domctl.c	Tue Jan 16 11:55:05 2007 -0500
+++ b/xen/arch/powerpc/domctl.c	Tue Jan 16 18:11:13 2007 -0500
@@ -116,3 +116,44 @@ long arch_do_domctl(struct xen_domctl *d
 
     return ret;
 }
+
+/*
+ * these routine implement bitmasks as uint8_t arrays for portability
+ */
+static inline int test_bit8(ulong nr, const uint8_t *addr)
+{
+	return (1U & (addr[nr >> 3] >> (nr & 15)));
+}
+
+static inline void set_bit8(ulong nr, uint8_t *addr)
+{
+	uint8_t bit = 1UL << (nr & 15);
+	uint8_t *p = addr + (nr >> 3);
+
+	*p |= bit;
+}
+
+
+void *long_to_byte_bitmap(uint8_t *bp, const ulong *lp, size_t n)
+{
+    int i;
+
+    memset(bp, 0, n);
+    for (i = 0; i < n * 8; i++) {
+        if (test_bit(i, lp))
+            set_bit8(i, bp);
+    }
+    return bp;
+}
+
+void *byte_to_long_bitmap(ulong *lp, const uint8_t *bp, size_t n)
+{
+    int i;
+
+    memset(lp, 0, n);
+    for (i = 0; i < n * 8; i++) {
+        if (test_bit8(i, bp))
+            __set_bit(i, lp); /* non-atomic */
+    }
+    return lp;
+}
diff -r a6813a652f39 xen/common/domctl.c
--- a/xen/common/domctl.c	Tue Jan 16 11:55:05 2007 -0500
+++ b/xen/common/domctl.c	Tue Jan 16 13:40:01 2007 -0500
@@ -32,6 +32,8 @@ void cpumask_to_xenctl_cpumap(
 {
     unsigned int guest_bytes, copy_bytes, i;
     uint8_t zero = 0;
+    uint8_t local[sizeof (*cpumask)];
+    void *ptr;
 
     if ( guest_handle_is_null(xenctl_cpumap->bitmap) )
         return;
@@ -39,9 +41,9 @@ void cpumask_to_xenctl_cpumap(
     guest_bytes = (xenctl_cpumap->nr_cpus + 7) / 8;
     copy_bytes  = min_t(unsigned int, guest_bytes, (NR_CPUS + 7) / 8);
 
-    copy_to_guest(xenctl_cpumap->bitmap,
-                  (uint8_t *)cpus_addr(*cpumask),
-                  copy_bytes);
+    ptr = long_to_byte_bitmap(local, cpus_addr(*cpumask), copy_bytes);
+
+    copy_to_guest(xenctl_cpumap->bitmap, ptr, copy_bytes);
 
     for ( i = copy_bytes; i < guest_bytes; i++ )
         copy_to_guest_offset(xenctl_cpumap->bitmap, i, &zero, 1);
@@ -51,6 +53,7 @@ void xenctl_cpumap_to_cpumask(
     cpumask_t *cpumask, struct xenctl_cpumap *xenctl_cpumap)
 {
     unsigned int guest_bytes, copy_bytes;
+    uint8_t local[sizeof (*cpumask)];
 
     guest_bytes = (xenctl_cpumap->nr_cpus + 7) / 8;
     copy_bytes  = min_t(unsigned int, guest_bytes, (NR_CPUS + 7) / 8);
@@ -60,9 +63,9 @@ void xenctl_cpumap_to_cpumask(
     if ( guest_handle_is_null(xenctl_cpumap->bitmap) )
         return;
 
-    copy_from_guest((uint8_t *)cpus_addr(*cpumask),
-                    xenctl_cpumap->bitmap,
-                    copy_bytes);
+    copy_from_guest(&local[0], xenctl_cpumap->bitmap, copy_bytes);
+
+    byte_to_long_bitmap(cpus_addr(*cpumask), local, copy_bytes);
 }
 
 static inline int is_free_domid(domid_t dom)
diff -r a6813a652f39 xen/include/public/arch-powerpc.h
--- a/xen/include/public/arch-powerpc.h	Tue Jan 16 11:55:05 2007 -0500
+++ b/xen/include/public/arch-powerpc.h	Tue Jan 16 17:53:30 2007 -0500
@@ -118,4 +118,6 @@ struct arch_vcpu_info {
 #define MAX_VIRT_CPUS 32
 #endif
 
+#define __HAVE_ARCH_BYTE_TO_LONG_BITMAP
+
 #endif
diff -r a6813a652f39 xen/include/public/domctl.h
--- a/xen/include/public/domctl.h	Tue Jan 16 11:55:05 2007 -0500
+++ b/xen/include/public/domctl.h	Tue Jan 16 18:09:55 2007 -0500
@@ -424,6 +424,16 @@ typedef struct xen_domctl xen_domctl_t;
 typedef struct xen_domctl xen_domctl_t;
 DEFINE_XEN_GUEST_HANDLE(xen_domctl_t);
 
+#ifdef __HAVE_ARCH_BYTE_TO_LONG_BITMAP
+extern void *long_to_byte_bitmap(uint8_t *bp, const ulong *lp,
+                                 size_t n);
+extern void *byte_to_long_bitmap(ulong *lp, const uint8_t *bp,
+                                 size_t n);
+#else
+#define long_to_byte_bitmap(bp, lp, s) ((void)bp, (void)s, lp)
+#define byte_to_long_bitmap(lp, bp, s) memcpy(lp, bp, s)
+#endif
+
 #endif /* __XEN_PUBLIC_DOMCTL_H__ */
 
 /*

  reply	other threads:[~2007-01-16 23:26 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-17 17:53 [PATCH] fix xenctl_cpumap translation to handle bitops accessed like arrays Jimi Xenidis
2006-12-18  9:26 ` Keir Fraser
2006-12-18 16:50   ` Jimi Xenidis
2006-12-18 17:55     ` Keir Fraser
2006-12-20 19:05       ` [RFC] " Jimi Xenidis
2006-12-21 10:48         ` Keir Fraser
2006-12-21 17:32           ` Jimi Xenidis
2006-12-21 19:51             ` Keir Fraser
2007-01-16 23:26               ` Jimi Xenidis [this message]
2007-01-17 12:20                 ` Keir Fraser
2007-01-17 12:50                   ` Jimi Xenidis
2007-01-17 13:55                     ` Keir Fraser
2007-01-21 16:10                       ` Jimi Xenidis
2007-01-21 16:20                         ` Keir Fraser
2007-01-21 21:43                           ` Jimi Xenidis

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=t16k5zmpn8k.fsf@pobox.com \
    --to=jimix@watson.ibm.com \
    --cc=keir@xensource.com \
    --cc=xen-devel@lists.xensource.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.