From patchwork Fri Mar 31 01:43:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Dai X-Patchwork-Id: 669181 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85693C761AF for ; Fri, 31 Mar 2023 01:44:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229697AbjCaBod (ORCPT ); Thu, 30 Mar 2023 21:44:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229664AbjCaBob (ORCPT ); Thu, 30 Mar 2023 21:44:31 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 698AA11E9E for ; Thu, 30 Mar 2023 18:44:23 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id y144-20020a253296000000b00b69ce0e6f2dso20617054yby.18 for ; Thu, 30 Mar 2023 18:44:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680227062; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=bQHMl9pwJydZAQbrAoDkSnvavcJ/jzjaFAvojHFhORk=; b=cE6t4ZFZ1GrVpjJSvVne/IoBs3nTvhJx2/x7tbZXEgJWa1Mk0XQ0npmPY8f/9VQI/r K75GmTXHd4epQTJXabgReN4I22zYPK7rPDu8IZR6IGBgbKDvzB9+b6UtiKkohpPFxoPX b2L7y9HVxegUECa/hEkNEht7jAlxcJ1tJvwL9ceHPnOFEWz/igzM3p3WSjHHgg7mxyp8 sRMKMOEZaZQ61niu5ApADy/l4UYir9EHW+X+ghjI8PIwO+2S4AVDQ9XYGpCJ//hJsLPh NDSDv2w67CQ/pth2hxiZBg6Ks/QMp3as8Oqh8rgVpxqdYgDkYf0aXake8sqaJq31zq8n /tIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680227062; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=bQHMl9pwJydZAQbrAoDkSnvavcJ/jzjaFAvojHFhORk=; b=23ZIZJxGCBoFEKiI2yC+YDDR2l5MMDpkcIMxOjsuFMSPZdeCBThDyTgml/FrC6G8hM QsWrKK2dmN0/3AFCsUNxtYVSrt0xMfFMZwlQ3y/gcTNsgtO4+k16kbu6O7rutPuWSl76 Z0LB00dqgyz7CYZFod32Aj2MrW3hDTTZnUrXV0r/7DZRx0UIQfGXrG4SRyCkWwzP/yXn Yq2pUChIElKJ7NCQh1ftFFIqkpsHLm8UiI1mqbQmRqqI8kAI6xPVSRCc/QqMEk212vwe P34fw6iOgbFI+1mXDG3hXoHqC9nrLCIrapNp606ajeGDLe/VqhIEd+FACLeTcMHohLJm xcGw== X-Gm-Message-State: AAQBX9dB/100rDCpzY8hwRDPab7XfdFQDuSgd29388SoQsMiJ/KL7uSW IlL9tnApVm/hWHHspI/N3QR34eDRFEQP X-Google-Smtp-Source: AKy350ZivNvxJZ18U+W1XPsWsfvpSQ+cLGN8Aj2+BZDUohIE+m0rmZgZiCfr6NdVfa3nqdRvfK2U2A2N5cMv X-Received: from davidai2.mtv.corp.google.com ([2620:15c:211:201:c162:24e8:ec5e:d520]) (user=davidai job=sendgmr) by 2002:a25:ab11:0:b0:a5f:0:bf12 with SMTP id u17-20020a25ab11000000b00a5f0000bf12mr12526269ybi.13.1680227062710; Thu, 30 Mar 2023 18:44:22 -0700 (PDT) Date: Thu, 30 Mar 2023 18:43:45 -0700 In-Reply-To: <20230331014356.1033759-1-davidai@google.com> Mime-Version: 1.0 References: <20230331014356.1033759-1-davidai@google.com> X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog Message-ID: <20230331014356.1033759-2-davidai@google.com> Subject: [RFC PATCH v2 1/6] sched/fair: Add util_guest for tasks From: David Dai To: "Rafael J. Wysocki" , Viresh Kumar , Rob Herring , Krzysztof Kozlowski , Paolo Bonzini , Jonathan Corbet , Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Mark Rutland , Lorenzo Pieralisi , Sudeep Holla , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , David Dai Cc: Saravana Kannan , kernel-team@android.com, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org For virtualization usecases, util_est and util_avg currently tracked on the host aren't sufficient to accurately represent the workload on vCPU threads, which results in poor frequency selection and performance. For example, when a large workload migrates from a busy vCPU thread to an idle vCPU thread, it incurs additional DVFS ramp-up latencies as util accumulates. Introduce a new "util_guest" member as an additional PELT signal that's independently updated by the guest. When used, it's max aggregated to provide a boost to both task_util and task_util_est. Updating task_util and task_util_est will ensure: -Better task placement decisions for vCPU threads on the host -Correctly updating util_est.ewma during dequeue -Additive util with other threads on the same runqueue for more accurate frequency responses Co-developed-by: Saravana Kannan Signed-off-by: Saravana Kannan Signed-off-by: David Dai --- include/linux/sched.h | 11 +++++++++++ kernel/sched/core.c | 18 +++++++++++++++++- kernel/sched/fair.c | 15 +++++++++++++-- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index 63d242164b1a..d8c346fcdf52 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -445,6 +445,16 @@ struct util_est { #define UTIL_AVG_UNCHANGED 0x80000000 } __attribute__((__aligned__(sizeof(u64)))); +/* + * For sched_setattr_nocheck() (kernel) only + * + * Allow vCPU threads to use UTIL_GUEST as a way to hint the scheduler with more + * accurate utilization info. This is useful when guest kernels have some way of + * tracking its own runqueue's utilization. + * + */ +#define SCHED_FLAG_UTIL_GUEST 0x20000000 + /* * The load/runnable/util_avg accumulates an infinite geometric series * (see __update_load_avg_cfs_rq() in kernel/sched/pelt.c). @@ -499,6 +509,7 @@ struct sched_avg { unsigned long load_avg; unsigned long runnable_avg; unsigned long util_avg; + unsigned long util_guest; struct util_est util_est; } ____cacheline_aligned; diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 0d18c3969f90..7700ef5610c1 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -2024,6 +2024,16 @@ static inline void uclamp_post_fork(struct task_struct *p) { } static inline void init_uclamp(void) { } #endif /* CONFIG_UCLAMP_TASK */ +static void __setscheduler_task_util(struct task_struct *p, + const struct sched_attr *attr) +{ + + if (likely(!(attr->sched_flags & SCHED_FLAG_UTIL_GUEST))) + return; + + p->se.avg.util_guest = attr->sched_util_min; +} + bool sched_task_on_rq(struct task_struct *p) { return task_on_rq_queued(p); @@ -7561,7 +7571,7 @@ static int __sched_setscheduler(struct task_struct *p, return -EINVAL; } - if (attr->sched_flags & ~(SCHED_FLAG_ALL | SCHED_FLAG_SUGOV)) + if (attr->sched_flags & ~(SCHED_FLAG_ALL | SCHED_FLAG_SUGOV | SCHED_FLAG_UTIL_GUEST)) return -EINVAL; /* @@ -7583,6 +7593,9 @@ static int __sched_setscheduler(struct task_struct *p, if (attr->sched_flags & SCHED_FLAG_SUGOV) return -EINVAL; + if (attr->sched_flags & SCHED_FLAG_UTIL_GUEST) + return -EINVAL; + retval = security_task_setscheduler(p); if (retval) return retval; @@ -7629,6 +7642,8 @@ static int __sched_setscheduler(struct task_struct *p, goto change; if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP) goto change; + if (attr->sched_flags & SCHED_FLAG_UTIL_GUEST) + goto change; p->sched_reset_on_fork = reset_on_fork; retval = 0; @@ -7718,6 +7733,7 @@ static int __sched_setscheduler(struct task_struct *p, __setscheduler_prio(p, newprio); } __setscheduler_uclamp(p, attr); + __setscheduler_task_util(p, attr); if (queued) { /* diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 6986ea31c984..998649554344 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -4276,14 +4276,16 @@ static int newidle_balance(struct rq *this_rq, struct rq_flags *rf); static inline unsigned long task_util(struct task_struct *p) { - return READ_ONCE(p->se.avg.util_avg); + return max(READ_ONCE(p->se.avg.util_avg), + READ_ONCE(p->se.avg.util_guest)); } static inline unsigned long _task_util_est(struct task_struct *p) { struct util_est ue = READ_ONCE(p->se.avg.util_est); - return max(ue.ewma, (ue.enqueued & ~UTIL_AVG_UNCHANGED)); + return max_t(unsigned long, READ_ONCE(p->se.avg.util_guest), + max(ue.ewma, (ue.enqueued & ~UTIL_AVG_UNCHANGED))); } static inline unsigned long task_util_est(struct task_struct *p) @@ -6242,6 +6244,15 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags) */ util_est_enqueue(&rq->cfs, p); + /* + * The normal code path for host thread enqueue doesn't take into + * account guest task migrations when updating cpufreq util. + * So, always update the cpufreq when a vCPU thread has a + * non-zero util_guest value. + */ + if (READ_ONCE(p->se.avg.util_guest)) + cpufreq_update_util(rq, 0); + /* * If in_iowait is set, the code below may not trigger any cpufreq * utilization updates, so do it here explicitly with the IOWAIT flag From patchwork Fri Mar 31 01:43:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Dai X-Patchwork-Id: 669180 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 804F7C7619A for ; Fri, 31 Mar 2023 01:45:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229745AbjCaBo7 (ORCPT ); Thu, 30 Mar 2023 21:44:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229629AbjCaBo6 (ORCPT ); Thu, 30 Mar 2023 21:44:58 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B21F818F98 for ; Thu, 30 Mar 2023 18:44:40 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-544781e30easo203470817b3.1 for ; Thu, 30 Mar 2023 18:44:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680227080; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=2nOCpsUj368/jlH6/5xvHY1SZiMoDDhdnoWB6M9IhGk=; b=EoFm2EESCZFa8L2EDfRrSWrK5iTwjplzrCG15Muuw4LexoEv7cRzk3U8mMFd31uCi3 VdC3YIAw664hHqw4YqXBm6NIsYVZI/zi6aI33HgKpvZUCAq2F60LsjTAND6zuqPnJWxw dUhoC0XEDFF41sRo/izu1KWyx6xV8dMdVZVnuum5wiMrH41XrpQhbpM81Y8B9/+a6HFg 6lHwXnBerygZWkfWkozFym/kgihFZNMZdJvJ2ILOzQHd1aU1GopN0D0mcKwbW+ctaONf 42O9oES/W+GB8HkYY0aFvEtljKmYDHH0edNbuZQCFHw6OO1bklTz6k1MVWQ4/ilgFj// cuBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680227080; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2nOCpsUj368/jlH6/5xvHY1SZiMoDDhdnoWB6M9IhGk=; b=oVaBvJxNTVfoKT8naA81bjXyJQHvw1qrg/6yGsvETznL7O98lzyIQYanXTS0a7pEfD IlJds49t4Xba53bIB17a2ZqU686F4DkB8Puki4pwI8cqNJ5ddgk0/vaas0tkurKj9VHg a4wohTY/6yvsqZbkvYiY2j1x0SkpX0hhKfsM9fg32j1rekZ9NBzHDLxTJ8oSQzInZREf lnyNFx7lI+IZmtb9qRaRM43HGReNPLUDrPimMzm05/l2enTQwTOYeuWHsMBd2Pp4qjgW GjldOhYReey5AO14cx57EKjVMvEN2BzdWiSdeLAd9KFnM+x2Qb14E5MC0IxucN7qVgUe xTtg== X-Gm-Message-State: AAQBX9fFhogXTSjCOsVIo7ynm/nTBN4kdInd29S6qlX+6y73BMMhPS8Y Eznv3ejx1MRIof8OUfdlzXXuzZHx5Fl9 X-Google-Smtp-Source: AKy350ba7fvAQLLeLUmDHWvV6pFnNpQ3WE7NZ+hQyM9RHczPn7Ji9dv9PUy3aXAqd4B7WromdF7iWfstQpkF X-Received: from davidai2.mtv.corp.google.com ([2620:15c:211:201:c162:24e8:ec5e:d520]) (user=davidai job=sendgmr) by 2002:a05:6902:168d:b0:b26:47f3:6cb with SMTP id bx13-20020a056902168d00b00b2647f306cbmr13590397ybb.4.1680227079917; Thu, 30 Mar 2023 18:44:39 -0700 (PDT) Date: Thu, 30 Mar 2023 18:43:47 -0700 In-Reply-To: <20230331014356.1033759-1-davidai@google.com> Mime-Version: 1.0 References: <20230331014356.1033759-1-davidai@google.com> X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog Message-ID: <20230331014356.1033759-4-davidai@google.com> Subject: [RFC PATCH v2 3/6] kvm: arm64: Add support for util_hint service From: David Dai To: "Rafael J. Wysocki" , Viresh Kumar , Rob Herring , Krzysztof Kozlowski , Paolo Bonzini , Jonathan Corbet , Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Mark Rutland , Lorenzo Pieralisi , Sudeep Holla , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , David Dai Cc: Saravana Kannan , kernel-team@android.com, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org This service allows guests to send the utilization of workoads on its vCPUs to the host. Utilization is represented as an arbitrary value of 0-1024 where 1024 represents the highest performance point normalized for frequency and architecture across all CPUs. This hint is used by the host for scheduling vCPU threads and deciding CPU frequency. Co-developed-by: Saravana Kannan Signed-off-by: Saravana Kannan Signed-off-by: David Dai --- Documentation/virt/kvm/api.rst | 12 ++++++++++++ Documentation/virt/kvm/arm/index.rst | 1 + Documentation/virt/kvm/arm/util_hint.rst | 22 ++++++++++++++++++++++ arch/arm64/include/uapi/asm/kvm.h | 1 + arch/arm64/kvm/arm.c | 1 + arch/arm64/kvm/hypercalls.c | 20 ++++++++++++++++++++ include/linux/arm-smccc.h | 7 +++++++ include/uapi/linux/kvm.h | 1 + tools/arch/arm64/include/uapi/asm/kvm.h | 1 + 9 files changed, 66 insertions(+) create mode 100644 Documentation/virt/kvm/arm/util_hint.rst diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index b0ff0ad700bf..38ce33564efc 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -8388,6 +8388,18 @@ must point to a byte where the value will be stored or retrieved from. This capability indicates that KVM supports getting the frequency of the current CPU that the vCPU thread is running on. +8.41 KVM_CAP_UTIL_HINT +---------------------- + +:Architectures: arm64 + +This capability indicates that the KVM supports taking utilization +hints from the guest. Utilization is represented as a value from 0-1024 +where 1024 represents the highest performance point across all physical CPUs +after normalizing for architecture. This is useful when guests are tracking +workload on its vCPUs. Util hints allow the host to make more accurate +frequency selections and task placement for vCPU threads. + 9. Known KVM API problems ========================= diff --git a/Documentation/virt/kvm/arm/index.rst b/Documentation/virt/kvm/arm/index.rst index 47afc5c1f24a..f83877663813 100644 --- a/Documentation/virt/kvm/arm/index.rst +++ b/Documentation/virt/kvm/arm/index.rst @@ -12,3 +12,4 @@ ARM pvtime ptp_kvm get_cur_cpufreq + util_hint diff --git a/Documentation/virt/kvm/arm/util_hint.rst b/Documentation/virt/kvm/arm/util_hint.rst new file mode 100644 index 000000000000..262d142d62d9 --- /dev/null +++ b/Documentation/virt/kvm/arm/util_hint.rst @@ -0,0 +1,22 @@ +.. SPDX-License-Identifier: GPL-2.0 + +Util_hint support for arm64 +============================ + +Util_hint is used for sharing the utilization value from the guest +to the host. + +* ARM_SMCCC_HYP_KVM_UTIL_HINT_FUNC_ID: 0x86000041 + +This hypercall using the SMC32/HVC32 calling convention: + +ARM_SMCCC_HYP_KVM_UTIL_HINT_FUNC_ID + ============== ========= ============================ + Function ID: (uint32) 0x86000041 + Arguments: (uint32) util value(0-1024) where 1024 represents + the highest performance point normalized + across all CPUs + Return values: (int32) NOT_SUPPORTED(-1) on error. + Endianness: Must be the same endianness + as the host. + ============== ======== ============================ diff --git a/arch/arm64/include/uapi/asm/kvm.h b/arch/arm64/include/uapi/asm/kvm.h index ed8b63e91bdc..61309ecb7241 100644 --- a/arch/arm64/include/uapi/asm/kvm.h +++ b/arch/arm64/include/uapi/asm/kvm.h @@ -368,6 +368,7 @@ enum { KVM_REG_ARM_VENDOR_HYP_BIT_FUNC_FEAT = 0, KVM_REG_ARM_VENDOR_HYP_BIT_PTP = 1, KVM_REG_ARM_VENDOR_HYP_BIT_GET_CUR_CPUFREQ = 2, + KVM_REG_ARM_VENDOR_HYP_BIT_UTIL_HINT = 3, #ifdef __KERNEL__ KVM_REG_ARM_VENDOR_HYP_BMAP_BIT_COUNT, #endif diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index f960b136c611..bf3c4d4b9b67 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -221,6 +221,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) case KVM_CAP_PTP_KVM: case KVM_CAP_ARM_SYSTEM_SUSPEND: case KVM_CAP_GET_CUR_CPUFREQ: + case KVM_CAP_UTIL_HINT: r = 1; break; case KVM_CAP_SET_GUEST_DEBUG2: diff --git a/arch/arm64/kvm/hypercalls.c b/arch/arm64/kvm/hypercalls.c index b3f4b90c024b..01dba07b5183 100644 --- a/arch/arm64/kvm/hypercalls.c +++ b/arch/arm64/kvm/hypercalls.c @@ -28,6 +28,20 @@ static void kvm_sched_get_cur_cpufreq(struct kvm_vcpu *vcpu, u64 *val) val[0] = ret_freq; } +static void kvm_sched_set_util(struct kvm_vcpu *vcpu, u64 *val) +{ + struct sched_attr attr = { + .sched_flags = SCHED_FLAG_UTIL_GUEST, + }; + int ret; + + attr.sched_util_min = smccc_get_arg1(vcpu); + + ret = sched_setattr_nocheck(current, &attr); + + val[0] = (u64)ret; +} + static void kvm_ptp_get_time(struct kvm_vcpu *vcpu, u64 *val) { struct system_time_snapshot systime_snapshot; @@ -131,6 +145,9 @@ static bool kvm_hvc_call_allowed(struct kvm_vcpu *vcpu, u32 func_id) case ARM_SMCCC_VENDOR_HYP_KVM_GET_CUR_CPUFREQ_FUNC_ID: return test_bit(KVM_REG_ARM_VENDOR_HYP_BIT_GET_CUR_CPUFREQ, &smccc_feat->vendor_hyp_bmap); + case ARM_SMCCC_VENDOR_HYP_KVM_UTIL_HINT_FUNC_ID: + return test_bit(KVM_REG_ARM_VENDOR_HYP_BIT_UTIL_HINT, + &smccc_feat->vendor_hyp_bmap); default: return kvm_hvc_call_default_allowed(func_id); } @@ -231,6 +248,9 @@ int kvm_hvc_call_handler(struct kvm_vcpu *vcpu) case ARM_SMCCC_VENDOR_HYP_KVM_GET_CUR_CPUFREQ_FUNC_ID: kvm_sched_get_cur_cpufreq(vcpu, val); break; + case ARM_SMCCC_VENDOR_HYP_KVM_UTIL_HINT_FUNC_ID: + kvm_sched_set_util(vcpu, val); + break; case ARM_SMCCC_TRNG_VERSION: case ARM_SMCCC_TRNG_FEATURES: case ARM_SMCCC_TRNG_GET_UUID: diff --git a/include/linux/arm-smccc.h b/include/linux/arm-smccc.h index e15f1bdcf3f1..9f747e5025b6 100644 --- a/include/linux/arm-smccc.h +++ b/include/linux/arm-smccc.h @@ -113,6 +113,7 @@ #define ARM_SMCCC_KVM_FUNC_FEATURES 0 #define ARM_SMCCC_KVM_FUNC_PTP 1 #define ARM_SMCCC_KVM_FUNC_GET_CUR_CPUFREQ 64 +#define ARM_SMCCC_KVM_FUNC_UTIL_HINT 65 #define ARM_SMCCC_KVM_FUNC_FEATURES_2 127 #define ARM_SMCCC_KVM_NUM_FUNCS 128 @@ -145,6 +146,12 @@ ARM_SMCCC_OWNER_VENDOR_HYP, \ ARM_SMCCC_KVM_FUNC_GET_CUR_CPUFREQ) +#define ARM_SMCCC_VENDOR_HYP_KVM_UTIL_HINT_FUNC_ID \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_32, \ + ARM_SMCCC_OWNER_VENDOR_HYP, \ + ARM_SMCCC_KVM_FUNC_UTIL_HINT) + /* Paravirtualised time calls (defined by ARM DEN0057A) */ #define ARM_SMCCC_HV_PV_TIME_FEATURES \ ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 0a1a260243bf..7f667ab344ae 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1185,6 +1185,7 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_DIRTY_LOG_RING_WITH_BITMAP 225 #define KVM_CAP_PMU_EVENT_MASKED_EVENTS 226 #define KVM_CAP_GET_CUR_CPUFREQ 512 +#define KVM_CAP_UTIL_HINT 513 #ifdef KVM_CAP_IRQ_ROUTING diff --git a/tools/arch/arm64/include/uapi/asm/kvm.h b/tools/arch/arm64/include/uapi/asm/kvm.h index ed8b63e91bdc..61309ecb7241 100644 --- a/tools/arch/arm64/include/uapi/asm/kvm.h +++ b/tools/arch/arm64/include/uapi/asm/kvm.h @@ -368,6 +368,7 @@ enum { KVM_REG_ARM_VENDOR_HYP_BIT_FUNC_FEAT = 0, KVM_REG_ARM_VENDOR_HYP_BIT_PTP = 1, KVM_REG_ARM_VENDOR_HYP_BIT_GET_CUR_CPUFREQ = 2, + KVM_REG_ARM_VENDOR_HYP_BIT_UTIL_HINT = 3, #ifdef __KERNEL__ KVM_REG_ARM_VENDOR_HYP_BMAP_BIT_COUNT, #endif From patchwork Fri Mar 31 01:43:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Dai X-Patchwork-Id: 669179 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF206C6FD1D for ; Fri, 31 Mar 2023 01:45:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229852AbjCaBp0 (ORCPT ); Thu, 30 Mar 2023 21:45:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229806AbjCaBpS (ORCPT ); Thu, 30 Mar 2023 21:45:18 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA07B18829 for ; Thu, 30 Mar 2023 18:45:00 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 204-20020a2514d5000000b00a3637aea9e1so20757588ybu.17 for ; Thu, 30 Mar 2023 18:45:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680227097; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=mcnJNCHDCGQ7Pzom/y/MQEMC0VEcznZRpNuHkAP16dM=; b=M/Dq0K05dn7RZdEyBco1zZW8o9aWbWD0tOGYp2aROenD9B8zG0YkXNU+ypXcmNaQHy 4te0VdM4kG75aRgDJAiNeipUhfEk+8e/2sx5TS12tTIKnwevTbmQxo+lHWm8c4GqVIme 9obizM0C3ozNmYHsi7lUhQIGaKT/Br4nuLulq8WoaCHOkuqxJMA1bY+CMXCC0ew5OUZ4 1jdQ0A+60hb3BK31NK4oiYIATEqSpKYaYoTbaF3+E58KDNOd+GbOm3KRIRxTxJKRucQs fJJk6ss0ykBavcFxwDBDlUhiJ9dG27uWdOFRP7shyzkO7Uda44T+RDaamnaXQVhGcf2m ufIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680227097; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=mcnJNCHDCGQ7Pzom/y/MQEMC0VEcznZRpNuHkAP16dM=; b=ks7v7/a/iHU27ceDiBOl/RIGm/X4mTLCp9yk1IbSCyXcH5oNjA3zgpXKLAxsZ4m0hW RSGD3elgj3LoZxbgI9tpHWLWp4CdfF1q4tEucbR+QrY8n3qwSsvqyE4cmBJA4Iqe1SEC 5cIe3Dqpuod097HvGyV3bKpS/MJ6mjmO7CW3ulOsy5Q/qURL5d0WfZRoLOvqhRdy+/hA G2LGd0uqjysAyiTZbX2Di5X2Nji8b+rIazyZ51MlriwC6mif/JqevkSDqFAiQjRYa5O1 9nBSEVgEe02QdYNQPNoGJbX3KUadWg0FQsFOe9k/UfnT6rjfMvJjP/+X6sS0ykpbecvD E8Tg== X-Gm-Message-State: AAQBX9fVBxOWVnl6t+qn1P6IITKLHXsa4Ml1DWu/b61agEwhsNht3xWN K4NjF+5002xl2SqdIPwIfzSK5H1o70DB X-Google-Smtp-Source: AKy350Yd56UldAkJl7asDkNCi90KnSNtQkBy2kVHq8vFVuOOr9KiBt3/jvgItL1ugb+qYv+7kMO0tDmyjIK9 X-Received: from davidai2.mtv.corp.google.com ([2620:15c:211:201:c162:24e8:ec5e:d520]) (user=davidai job=sendgmr) by 2002:a25:344:0:b0:b27:4632:f651 with SMTP id 65-20020a250344000000b00b274632f651mr12517637ybd.3.1680227097054; Thu, 30 Mar 2023 18:44:57 -0700 (PDT) Date: Thu, 30 Mar 2023 18:43:49 -0700 In-Reply-To: <20230331014356.1033759-1-davidai@google.com> Mime-Version: 1.0 References: <20230331014356.1033759-1-davidai@google.com> X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog Message-ID: <20230331014356.1033759-6-davidai@google.com> Subject: [RFC PATCH v2 5/6] dt-bindings: cpufreq: add bindings for virtual kvm cpufreq From: David Dai To: "Rafael J. Wysocki" , Viresh Kumar , Rob Herring , Krzysztof Kozlowski , Paolo Bonzini , Jonathan Corbet , Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Mark Rutland , Lorenzo Pieralisi , Sudeep Holla , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , David Dai Cc: Saravana Kannan , kernel-team@android.com, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Add devicetree bindings for a virtual kvm cpufreq driver. Co-developed-by: Saravana Kannan Signed-off-by: Saravana Kannan Signed-off-by: David Dai --- .../bindings/cpufreq/cpufreq-virtual-kvm.yaml | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Documentation/devicetree/bindings/cpufreq/cpufreq-virtual-kvm.yaml diff --git a/Documentation/devicetree/bindings/cpufreq/cpufreq-virtual-kvm.yaml b/Documentation/devicetree/bindings/cpufreq/cpufreq-virtual-kvm.yaml new file mode 100644 index 000000000000..31e64558a7f1 --- /dev/null +++ b/Documentation/devicetree/bindings/cpufreq/cpufreq-virtual-kvm.yaml @@ -0,0 +1,39 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/cpufreq/cpufreq-virtual-kvm.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Virtual KVM CPUFreq + +maintainers: + - David Dai + +description: | + + KVM CPUFreq is a virtualized driver in guest kernels that sends utilization + of its vCPUs as a hint to the host. The host uses hint to schedule vCPU + threads and select CPU frequency. It enables accurate Per-Entity Load + Tracking for tasks running in the guest by querying host CPU frequency + unless a virtualized FIE exists(Like AMUs). + +properties: + compatible: + const: virtual,kvm-cpufreq + +required: + - compatible + +additionalProperties: false + +examples: + - | + { + #address-cells = <2>; + #size-cells = <2>; + + cpufreq { + compatible = "virtual,kvm-cpufreq"; + }; + + };