* [Qemu-devel] [PATCH] linux-user: implement sched_{g,s}etaffinity
@ 2011-01-27 2:16 Mike Frysinger
2011-02-01 8:50 ` [Qemu-devel] [PATCH v2] linux-user: implement sched_{g, s}etaffinity Mike Frysinger
0 siblings, 1 reply; 2+ messages in thread
From: Mike Frysinger @ 2011-01-27 2:16 UTC (permalink / raw)
To: qemu-devel, Riku Voipio
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
linux-user/syscall.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 50 insertions(+), 0 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 3e285c6..f95429f 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -235,6 +235,12 @@ _syscall6(int,sys_futex,int *,uaddr,int,op,int,val,
const struct timespec *,timeout,int *,uaddr2,int,val3)
#endif
#endif
+#define __NR_sys_sched_getaffinity __NR_sched_getaffinity
+_syscall3(int, sys_sched_getaffinity, pid_t, pid, unsigned int, len,
+ unsigned long *, user_mask_ptr);
+#define __NR_sys_sched_setaffinity __NR_sched_setaffinity
+_syscall3(int, sys_sched_setaffinity, pid_t, pid, unsigned int, len,
+ unsigned long *, user_mask_ptr);
static bitmask_transtbl fcntl_flags_tbl[] = {
{ TARGET_O_ACCMODE, TARGET_O_WRONLY, O_ACCMODE, O_WRONLY, },
@@ -6374,6 +6380,50 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
return value. */
ret = -TARGET_ENOTDIR;
break;
+ case TARGET_NR_sched_getaffinity:
+ {
+ unsigned int num_sets, host_mask_size, i;
+ unsigned long *host_mask;
+ abi_ulong *target_mask;
+
+ num_sets = arg2 / sizeof(abi_ulong);
+ host_mask_size = num_sets * sizeof(*host_mask);
+ host_mask = alloca(host_mask_size);
+
+ ret = get_errno(sys_sched_getaffinity(arg1, host_mask_size, host_mask));
+
+ if (!is_error(ret)) {
+ if (!lock_user_struct(VERIFY_WRITE, target_mask, arg3, 0)) {
+ goto efault;
+ }
+ for (i = 0; i < num_sets; ++i) {
+ target_mask[i] = tswapl(host_mask[i]);
+ }
+ unlock_user_struct(target_mask, arg2, 1);
+ }
+ }
+ break;
+ case TARGET_NR_sched_setaffinity:
+ {
+ unsigned int num_sets, host_mask_size, i;
+ unsigned long *host_mask;
+ abi_ulong *target_mask;
+
+ num_sets = arg2 / sizeof(abi_ulong);
+ host_mask_size = num_sets * sizeof(*host_mask);
+ host_mask = alloca(host_mask_size);
+
+ if (!lock_user_struct(VERIFY_READ, target_mask, arg3, 1)) {
+ goto efault;
+ }
+ for (i = 0; i < num_sets; ++i) {
+ host_mask[i] = tswapl(target_mask[i]);
+ }
+ unlock_user_struct(target_mask, arg2, 0);
+
+ ret = get_errno(sys_sched_setaffinity(arg1, host_mask_size, host_mask));
+ }
+ break;
case TARGET_NR_sched_setparam:
{
struct sched_param *target_schp;
--
1.7.4.rc2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [Qemu-devel] [PATCH v2] linux-user: implement sched_{g, s}etaffinity
2011-01-27 2:16 [Qemu-devel] [PATCH] linux-user: implement sched_{g,s}etaffinity Mike Frysinger
@ 2011-02-01 8:50 ` Mike Frysinger
0 siblings, 0 replies; 2+ messages in thread
From: Mike Frysinger @ 2011-02-01 8:50 UTC (permalink / raw)
To: qemu-devel, Riku Voipio
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
v2
- handle host/target size mismatches (32 on a 64)
linux-user/syscall.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 67 insertions(+), 0 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 64ba768..e405f56 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -235,6 +235,12 @@ _syscall6(int,sys_futex,int *,uaddr,int,op,int,val,
const struct timespec *,timeout,int *,uaddr2,int,val3)
#endif
#endif
+#define __NR_sys_sched_getaffinity __NR_sched_getaffinity
+_syscall3(int, sys_sched_getaffinity, pid_t, pid, unsigned int, len,
+ unsigned long *, user_mask_ptr);
+#define __NR_sys_sched_setaffinity __NR_sched_setaffinity
+_syscall3(int, sys_sched_setaffinity, pid_t, pid, unsigned int, len,
+ unsigned long *, user_mask_ptr);
static bitmask_transtbl fcntl_flags_tbl[] = {
{ TARGET_O_ACCMODE, TARGET_O_WRONLY, O_ACCMODE, O_WRONLY, },
@@ -6374,6 +6380,67 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
return value. */
ret = -TARGET_ENOTDIR;
break;
+ case TARGET_NR_sched_getaffinity:
+ {
+ unsigned int mask_size;
+ unsigned long *mask;
+
+ /*
+ * sched_getaffinity needs multiples of ulong, so need to take
+ * care of mismatches between target ulong and host ulong sizes.
+ */
+ if (arg2 & (sizeof(abi_ulong) - 1)) {
+ ret = -TARGET_EINVAL;
+ break;
+ }
+ mask_size = (arg2 + (sizeof(*mask) - 1)) & ~(sizeof(*mask) - 1);
+
+ mask = alloca(mask_size);
+ ret = get_errno(sys_sched_getaffinity(arg1, mask_size, mask));
+
+ if (!is_error(ret)) {
+ if (arg2 > ret) {
+ /* Zero out any extra space kernel didn't fill */
+ unsigned long zero = arg2 - ret;
+ p = alloca(zero);
+ memset(p, 0, zero);
+ if (copy_to_user(arg3 + zero, p, zero)) {
+ goto efault;
+ }
+ arg2 = ret;
+ }
+ if (copy_to_user(arg3, mask, arg2)) {
+ goto efault;
+ }
+ ret = arg2;
+ }
+ }
+ break;
+ case TARGET_NR_sched_setaffinity:
+ {
+ unsigned int mask_size;
+ unsigned long *mask;
+
+ /*
+ * sched_setaffinity needs multiples of ulong, so need to take
+ * care of mismatches between target ulong and host ulong sizes.
+ */
+ if (arg2 & (sizeof(abi_ulong) - 1)) {
+ ret = -TARGET_EINVAL;
+ break;
+ }
+ mask_size = (arg2 + (sizeof(*mask) - 1)) & ~(sizeof(*mask) - 1);
+
+ mask = alloca(mask_size);
+ if (!lock_user_struct(VERIFY_READ, p, arg3, 1)) {
+ goto efault;
+ }
+ memcpy(mask, p, arg2);
+ unlock_user_struct(p, arg2, 0);
+
+ ret = get_errno(sys_sched_setaffinity(arg1, mask_size, mask));
+ }
+ break;
case TARGET_NR_sched_setparam:
{
struct sched_param *target_schp;
--
1.7.4.rc3
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-02-01 8:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-27 2:16 [Qemu-devel] [PATCH] linux-user: implement sched_{g,s}etaffinity Mike Frysinger
2011-02-01 8:50 ` [Qemu-devel] [PATCH v2] linux-user: implement sched_{g, s}etaffinity Mike Frysinger
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.