From patchwork Sun Jun 10 03:01:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 138124 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp2593558lji; Sat, 9 Jun 2018 20:38:28 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIkAWDIUChVMfs/LnTwYSeMPG2hfl9AnQCdKwAkGTzeuI6lf1/ROmtFu37NzQBq5bxc8ZfI X-Received: by 2002:a37:7d42:: with SMTP id y63-v6mr10052129qkc.293.1528601908577; Sat, 09 Jun 2018 20:38:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528601908; cv=none; d=google.com; s=arc-20160816; b=y3imSJOcoKbemo3iuIkkNXaUR5MPzcEWmeeiUG7B06F85Lt5LQQOT6tDOEI+yBPnRQ PilPuumyGhBQZSPg6q3cqyApvyecSyz/z9FU2XcsS53fvI3iOMo7W9iefUX5dxgF00PG S3ocSqF8NgngCl4GqxEjzB2DrvZuz5j78L6U1GosrNkVqFuvHKEHB1zfdELpuYRNBqLx Ns+lFYcS6fdwzergG3lU3+pyhwTA3s5qbsb1jJw5shYD3q/TfOVO6HrSYUGkr33SkA10 zr9WbmEZ+o2ykklBqrKhEMvcTB3TCl0X1ASD/RBXJlLENMJaRSG/s9TwssAHjjcn9Gp/ YfsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=Lf8heLOQnvP3Ys1IsclJ1J79nLc1YRq7KLkfBimhTZA=; b=KH4SHh9AsX12LMh1favCPwCYEn+6q7+C4nh0azL7U10VmgWVZlhFgxZk0lPWml5D/C DztoPrrwWO0GB6CJ8OePYFGI7UdvmouNRHYsmq00m67ZE8SQAy9DrJwp0zU0I6l1MfCR szVMq2zhJqytgsecHqbUhpMLDig3L1ria4ZIswd5NVYeBnX11RuqIzj7mLlbQr4fxGIb 7FL5eTiPWp2CWp/JmQPWWPXLGKom9IMYo0afBbci6J8EmqCBiRH58DbASOegQFHIpY6n ZHGfJpM7Jazd75X3gHg/fTSfirIz4etflR+bauGV6ApkjBVrlau+2ZbKLnk/QjUAzzEB ZsNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=P51sUvGk; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 23-v6si653677qtu.370.2018.06.09.20.38.28 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 09 Jun 2018 20:38:28 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=P51sUvGk; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42371 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRrBU-0007zO-18 for patch@linaro.org; Sat, 09 Jun 2018 23:38:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41021) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRqeu-0003Zc-Do for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:04:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fRqer-0003xv-7l for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:04:48 -0400 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]:42525) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fRqeq-0003wg-Vz for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:04:45 -0400 Received: by mail-pg0-x244.google.com with SMTP id c10-v6so2509166pgu.9 for ; Sat, 09 Jun 2018 20:04:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Lf8heLOQnvP3Ys1IsclJ1J79nLc1YRq7KLkfBimhTZA=; b=P51sUvGkUvqd4ZbifxPnkrOdnFWusmwmzCxo4qn5NJl08wEwgqq+uEjhrg2u0KwIt4 MemLHMkpBG89zg2HsY3JCzDkmQLs9BtSXmAD1ehqlG68Fc+HsXXceRe7h8aAkl969fQ7 OlSw7RMh3EvPR5504N6ArbdkMcbBKyfXOqtgA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Lf8heLOQnvP3Ys1IsclJ1J79nLc1YRq7KLkfBimhTZA=; b=mYdpA+hW1Jk4BBKKUz3GLStxGmm1q//3ZOywGtQBDvUfUEKHgXhOTpUKZTSGp9CnHo H0M+gkaVaxjHcvFMx8UWoQw29Z+KAbJ6jE9ZNWMkCC8xaUTlGBLnAFaKblaO17WO4EGv ManflH9d+zIjypZuq91r6fqJrRN/HTflJ7+zgApr2hQ+wU7BIBDHZIUTC1+8cialx3Om RlM1YDqgGbbq8BPst9/I46EIN/OjhyW0S2ia2FsxVcNO55pstWpI6bX5NKHJzB3NSOd8 x4ZR9uc7UOB0OEkchcpBfeeLwnIK62dSDxqDolkrH7IQ401aKUYDWizHW1v/D6nEBlU7 Il2w== X-Gm-Message-State: APt69E1XEJ+RrekAZGYzU+T3QLB/BAReUtnITuh1eV3CQtI1JRiswpQA 1qpN9Sn6HJ4gngxWs87Iu+QLKBYtrqw= X-Received: by 2002:a65:630b:: with SMTP id g11-v6mr10224989pgv.303.1528599883717; Sat, 09 Jun 2018 20:04:43 -0700 (PDT) Received: from cloudburst.twiddle.net (rrcs-173-198-77-219.west.biz.rr.com. [173.198.77.219]) by smtp.gmail.com with ESMTPSA id y17-v6sm31712718pfe.33.2018.06.09.20.04.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 09 Jun 2018 20:04:42 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 9 Jun 2018 17:01:36 -1000 Message-Id: <20180610030220.3777-65-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180610030220.3777-1-richard.henderson@linaro.org> References: <20180610030220.3777-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::244 Subject: [Qemu-devel] [PATCH v2 064/108] linux-user: Split out sched syscalls X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This includes sched_getaffinity, sched_getparam, sched_get_priority_max, sched_get_priority_min, sched_getscheduler, sched_rr_get_interval, sched_setaffinity, sched_setparam, sched_setscheduler, sched_yield. Signed-off-by: Richard Henderson --- linux-user/syscall.c | 281 ++++++++++++++++++++++++------------------- 1 file changed, 158 insertions(+), 123 deletions(-) -- 2.17.1 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 1907b32499..84f21634c8 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -9795,6 +9795,154 @@ IMPL(rt_tgsigqueueinfo) return get_errno(sys_rt_tgsigqueueinfo(arg1, arg2, arg3, &uinfo)); } +IMPL(sched_getaffinity) +{ + unsigned int mask_size; + unsigned long *mask; + abi_long ret; + + /* + * 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)) { + return -TARGET_EINVAL; + } + mask_size = QEMU_ALIGN_UP(arg2, sizeof(unsigned long)); + mask = alloca(mask_size); + memset(mask, 0, mask_size); + + ret = get_errno(sys_sched_getaffinity(arg1, mask_size, mask)); + if (!is_error(ret)) { + if (ret > arg2) { + /* More data returned than the caller's buffer will fit. + * This only happens if sizeof(abi_long) < sizeof(long) + * and the caller passed us a buffer holding an odd number + * of abi_longs. If the host kernel is actually using the + * extra 4 bytes then fail EINVAL; otherwise we can just + * ignore them and only copy the interesting part. + */ + int numcpus = sysconf(_SC_NPROCESSORS_CONF); + if (numcpus > arg2 * 8) { + return -TARGET_EINVAL; + } + ret = arg2; + } + if (host_to_target_cpu_mask(mask, mask_size, arg3, ret)) { + return -TARGET_EFAULT; + } + } + return ret; +} + +IMPL(sched_getparam) +{ + struct sched_param *target_schp; + struct sched_param schp; + abi_long ret; + + if (arg2 == 0) { + return -TARGET_EINVAL; + } + ret = get_errno(sched_getparam(arg1, &schp)); + if (!is_error(ret)) { + if (!lock_user_struct(VERIFY_WRITE, target_schp, arg2, 0)) { + return -TARGET_EFAULT; + } + target_schp->sched_priority = tswap32(schp.sched_priority); + unlock_user_struct(target_schp, arg2, 1); + } + return ret; +} + +IMPL(sched_get_priority_max) +{ + return get_errno(sched_get_priority_max(arg1)); +} + +IMPL(sched_get_priority_min) +{ + return get_errno(sched_get_priority_min(arg1)); +} + +IMPL(sched_getscheduler) +{ + return get_errno(sched_getscheduler(arg1)); +} + +IMPL(sched_rr_get_interval) +{ + struct timespec ts; + abi_long ret; + + ret = get_errno(sched_rr_get_interval(arg1, &ts)); + if (!is_error(ret)) { + ret = host_to_target_timespec(arg2, &ts); + } + return ret; +} + +IMPL(sched_setaffinity) +{ + unsigned int mask_size; + unsigned long *mask; + abi_long ret; + + /* + * 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)) { + return -TARGET_EINVAL; + } + mask_size = QEMU_ALIGN_UP(arg2, sizeof(unsigned long)); + mask = alloca(mask_size); + + ret = target_to_host_cpu_mask(mask, mask_size, arg3, arg2); + if (ret) { + return ret; + } + + return get_errno(sys_sched_setaffinity(arg1, mask_size, mask)); +} + +IMPL(sched_setparam) +{ + struct sched_param *target_schp; + struct sched_param schp; + + if (arg2 == 0) { + return -TARGET_EINVAL; + } + if (!lock_user_struct(VERIFY_READ, target_schp, arg2, 1)) { + return -TARGET_EFAULT; + } + schp.sched_priority = tswap32(target_schp->sched_priority); + unlock_user_struct(target_schp, arg2, 0); + return get_errno(sched_setparam(arg1, &schp)); +} + +IMPL(sched_setscheduler) +{ + struct sched_param *target_schp; + struct sched_param schp; + + if (arg3 == 0) { + return -TARGET_EINVAL; + } + if (!lock_user_struct(VERIFY_READ, target_schp, arg3, 1)) { + return -TARGET_EFAULT; + } + schp.sched_priority = tswap32(target_schp->sched_priority); + unlock_user_struct(target_schp, arg3, 0); + return get_errno(sched_setscheduler(arg1, arg2, &schp)); +} + +IMPL(sched_yield) +{ + return get_errno(sched_yield()); +} + #ifdef TARGET_NR_sgetmask IMPL(sgetmask) { @@ -10859,68 +11007,6 @@ static abi_long do_syscall1(void *cpu_env, unsigned num, abi_long arg1, void *p; switch(num) { - 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)) { - return -TARGET_EINVAL; - } - mask_size = (arg2 + (sizeof(*mask) - 1)) & ~(sizeof(*mask) - 1); - - mask = alloca(mask_size); - memset(mask, 0, mask_size); - ret = get_errno(sys_sched_getaffinity(arg1, mask_size, mask)); - - if (!is_error(ret)) { - if (ret > arg2) { - /* More data returned than the caller's buffer will fit. - * This only happens if sizeof(abi_long) < sizeof(long) - * and the caller passed us a buffer holding an odd number - * of abi_longs. If the host kernel is actually using the - * extra 4 bytes then fail EINVAL; otherwise we can just - * ignore them and only copy the interesting part. - */ - int numcpus = sysconf(_SC_NPROCESSORS_CONF); - if (numcpus > arg2 * 8) { - return -TARGET_EINVAL; - } - ret = arg2; - } - - if (host_to_target_cpu_mask(mask, mask_size, arg3, ret)) { - return -TARGET_EFAULT; - } - } - } - return ret; - 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)) { - return -TARGET_EINVAL; - } - mask_size = (arg2 + (sizeof(*mask) - 1)) & ~(sizeof(*mask) - 1); - mask = alloca(mask_size); - - ret = target_to_host_cpu_mask(mask, mask_size, arg3, arg2); - if (ret) { - return ret; - } - - return get_errno(sys_sched_setaffinity(arg1, mask_size, mask)); - } case TARGET_NR_getcpu: { unsigned cpu, node; @@ -10938,67 +11024,6 @@ static abi_long do_syscall1(void *cpu_env, unsigned num, abi_long arg1, } } return ret; - case TARGET_NR_sched_setparam: - { - struct sched_param *target_schp; - struct sched_param schp; - - if (arg2 == 0) { - return -TARGET_EINVAL; - } - if (!lock_user_struct(VERIFY_READ, target_schp, arg2, 1)) - return -TARGET_EFAULT; - schp.sched_priority = tswap32(target_schp->sched_priority); - unlock_user_struct(target_schp, arg2, 0); - return get_errno(sched_setparam(arg1, &schp)); - } - case TARGET_NR_sched_getparam: - { - struct sched_param *target_schp; - struct sched_param schp; - - if (arg2 == 0) { - return -TARGET_EINVAL; - } - ret = get_errno(sched_getparam(arg1, &schp)); - if (!is_error(ret)) { - if (!lock_user_struct(VERIFY_WRITE, target_schp, arg2, 0)) - return -TARGET_EFAULT; - target_schp->sched_priority = tswap32(schp.sched_priority); - unlock_user_struct(target_schp, arg2, 1); - } - } - return ret; - case TARGET_NR_sched_setscheduler: - { - struct sched_param *target_schp; - struct sched_param schp; - if (arg3 == 0) { - return -TARGET_EINVAL; - } - if (!lock_user_struct(VERIFY_READ, target_schp, arg3, 1)) - return -TARGET_EFAULT; - schp.sched_priority = tswap32(target_schp->sched_priority); - unlock_user_struct(target_schp, arg3, 0); - return get_errno(sched_setscheduler(arg1, arg2, &schp)); - } - case TARGET_NR_sched_getscheduler: - return get_errno(sched_getscheduler(arg1)); - case TARGET_NR_sched_yield: - return get_errno(sched_yield()); - case TARGET_NR_sched_get_priority_max: - return get_errno(sched_get_priority_max(arg1)); - case TARGET_NR_sched_get_priority_min: - return get_errno(sched_get_priority_min(arg1)); - case TARGET_NR_sched_rr_get_interval: - { - struct timespec ts; - ret = get_errno(sched_rr_get_interval(arg1, &ts)); - if (!is_error(ret)) { - ret = host_to_target_timespec(arg2, &ts); - } - } - return ret; case TARGET_NR_nanosleep: { struct timespec req, rem; @@ -13139,6 +13164,16 @@ static impl_fn *syscall_table(unsigned num) SYSCALL(rt_sigsuspend); SYSCALL(rt_sigtimedwait); SYSCALL(rt_tgsigqueueinfo); + SYSCALL(sched_getaffinity); + SYSCALL(sched_getparam); + SYSCALL(sched_get_priority_max); + SYSCALL(sched_get_priority_min); + SYSCALL(sched_getscheduler); + SYSCALL(sched_rr_get_interval); + SYSCALL(sched_setaffinity); + SYSCALL(sched_setparam); + SYSCALL(sched_setscheduler); + SYSCALL(sched_yield); #ifdef TARGET_NR_sgetmask SYSCALL(sgetmask); #endif