From mboxrd@z Thu Jan 1 00:00:00 1970 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 62CABCD98E2 for ; Wed, 17 Jun 2026 09:26:21 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.1339914.1600952 (Exim 4.92) (envelope-from ) id 1wZmXE-0004ul-Eb; Wed, 17 Jun 2026 09:26:12 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1339914.1600952; Wed, 17 Jun 2026 09:26:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wZmXE-0004ue-Bi; Wed, 17 Jun 2026 09:26:12 +0000 Received: by outflank-mailman (input) for mailman id 1339914; Wed, 17 Jun 2026 09:26:11 +0000 Received: from mx.expurgate.net ([195.190.135.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wZmXC-0004uV-KI for xen-devel@lists.xenproject.org; Wed, 17 Jun 2026 09:26:11 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wZmXC-008MKV-0x for xen-devel@lists.xenproject.org; Wed, 17 Jun 2026 11:26:10 +0200 Received: from [10.42.69.12] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a326829-2eae-0a2a0a5409dd-0a2a450c8996-36 for ; Wed, 17 Jun 2026 11:26:09 +0200 Received: from [209.85.221.46] (helo=mail-wr1-f46.google.com) by tlsNG-d25034.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a326831-62f1-0a2a450c0019-d155dd2ec0ae-3 for ; Wed, 17 Jun 2026 11:26:09 +0200 Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-45eea68dd6fso2986788f8f.2 for ; Wed, 17 Jun 2026 02:26:09 -0700 (PDT) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4606f26392esm51791832f8f.3.2026.06.17.02.26.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 17 Jun 2026 02:26:09 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=google header.d=suse.com header.i="@suse.com" header.h="Content-Transfer-Encoding:In-Reply-To:Autocrypt:Content-Language:References:Cc:To:From:Subject:User-Agent:MIME-Version:Date:Message-ID" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1781688369; x=1782293169; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=W7ffuk5mo5kC1dorjho/tlbgKEVDTzPAjrxyPKRjl9g=; b=DYrh9t6X4PGiakpu4GttCqK4TXJL26jgXSgaAoWG9gcQoUVbfUmC2wROdddFF3koVN Bzx7y5fz7u/fchlWBJn8xLdE8k+CqKIwGXKgLDWhPjmx/WZpppAIzyypJDw5OdNFZjKi bKyU+2zcnsZQ12TqybfFnS9EhjZ3BbCpkYh9k5RCj6BIuykq/IDFYoPsAvKPYwLzLj/c bKrUKqyeUA3f/AWmLqpSD74fJ1CWlBrUl3Il2bv5jhKMoz/tjzA/amlygZYHYk6hQs6z l22oWryuSN5eGh1oki8r2zth3KW+z4XGMAeh7Wbp5/r9uSEUX1DaPht4yCcYLevxXjDM w97A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781688369; x=1782293169; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=W7ffuk5mo5kC1dorjho/tlbgKEVDTzPAjrxyPKRjl9g=; b=ikq9AIDyoP4IX0b7FMRFzPGU6IBsehCbmlPdR0t5LaNss55RhlJUuSmtuKal3JruN4 EwabJyWslBXuWNn4yLNfZ9VhDCHEZZUPGe8dTFYeV+k+0LsCca7opqteyXhH9yc74N65 OsOoDoPgcbAEOMT9Pbub7ZhAGY8ACMYoRIjwBZHKBaaXffo/ylanJ29yMwFaHvxx2q8a kauTCVBTvaee1GYlG4mpc4/MdNMQlw9TwrxeMg/MWDPMC8P2npLmIU6T5J50edxnqwMB WHdjwHw+ML/71vsRpfQh0mCpj4bX3g+3EpydWrZrFFoQRrVxWQjPQXnXb2IB78NRlY1S x+Sg== X-Gm-Message-State: AOJu0YwZbF6rtm0pPpK++pmeSOResLL/CeWlg0/lDtkJnbronSYsrFXc pbkK0mW+J7TLN9DprRkj+mwnfEefwQO9k+xMJZuTg5D+ytOdnkpOkY4I3UpfJ+/TJjFXZp3mP4v QA5s= X-Gm-Gg: AfdE7cnpyV2yx14zKsTdY6ZJfhRhbd3eLY+cR4pxDuSDfsP9nYV1JztDjDj0fbdUZH3 aVOKW43EShJ57kodm+lMjau2Riw0Td4VPKnRwKsPyZPHgVtDhXzkZmV07QHLsgaQ+doIxWzoh1P EhjcfJjK+N2R6GqHW/FOsmfe7TngFCCbcceUxWilZyMkr7VJ4AN4erMep7pZd2lm6P/jEZBfv/x 4dy6MwF+SWVIjNm+Y9OFcMYLiorJg7LgWbv8UFGoAZNSwGLK+GvMoPi8KFRIv6stlOidV+GImLO EKqdH0rw1OKuBVfPMU6IdI+xY96U0b6SEKbnsqPn1guDZ0DrDb8jijWGkwKitnRmncHk/Lhb/wh yIgKdzW4uUs7RBoifZkHLccGejqq+GLthEksrd5LRN6Aky/IsAAgTOiSG+CQOjmGBiCxMvNq9Az 9z1a4QKpzpov/hrgAj1NhQZF1s1cDZ9nlfMteOb9halwt5IMdRw+SrCLksRp4K2ePmzg0QaWusd 6gl X-Received: by 2002:adf:ea10:0:b0:460:e0f:8d19 with SMTP id ffacd0b85a97d-4623f2e7ecbmr3775007f8f.9.1781688369325; Wed, 17 Jun 2026 02:26:09 -0700 (PDT) Message-ID: Date: Wed, 17 Jun 2026 11:26:08 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 for-4.22? 1/7] sched: introduce specialization of "running only" vcpu_runstate_get() From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Julien Grall , Stefano Stabellini , Anthony PERARD , Michal Orzel , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= , Oleksii Kurochko , Dario Faggioli , Juergen Gross , George Dunlap References: Content-Language: en-US Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s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content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-purgate-ID: tlsNG-d25034/1781688369-E2B74CF5-56D77134/0/0 X-purgate-type: clean X-purgate-size: 3762 About half the callers of vcpu_runstate_get() are solely after the "running" time of a vCPU. Introduce a specialization with a smaller read critical section and thus reduced risk of a need for retries. Signed-off-by: Jan Beulich Acked-by: Roger Pau Monné Reviewed-by: Juergen Gross --- The function name was chosen such that grep-ing for "vcpu_runstate_get" would still turn up all uses. If that was deemed largely irrelevant, a better name might be e.g. vcpu_get_running_time(). --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -56,7 +56,6 @@ void getdomaininfo(struct domain *d, str struct vcpu *v; u64 cpu_time = 0; int flags = XEN_DOMINF_blocked; - struct vcpu_runstate_info runstate; memset(info, 0, sizeof(*info)); @@ -69,8 +68,7 @@ void getdomaininfo(struct domain *d, str */ for_each_vcpu ( d, v ) { - vcpu_runstate_get(v, &runstate); - cpu_time += runstate.time[RUNSTATE_running]; + cpu_time += vcpu_runstate_get_running(v); info->max_vcpu_id = v->vcpu_id; if ( !(v->pause_flags & VPF_down) ) { @@ -796,8 +794,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xe case XEN_DOMCTL_getvcpuinfo: { - struct vcpu *v; - struct vcpu_runstate_info runstate; + const struct vcpu *v; ret = -EINVAL; if ( op->u.getvcpuinfo.vcpu >= d->max_vcpus ) @@ -807,12 +804,10 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xe if ( (v = d->vcpu[op->u.getvcpuinfo.vcpu]) == NULL ) break; - vcpu_runstate_get(v, &runstate); - op->u.getvcpuinfo.online = !(v->pause_flags & VPF_down); op->u.getvcpuinfo.blocked = !!(v->pause_flags & VPF_blocked); op->u.getvcpuinfo.running = v->is_running; - op->u.getvcpuinfo.cpu_time = runstate.time[RUNSTATE_running]; + op->u.getvcpuinfo.cpu_time = vcpu_runstate_get_running(v); op->u.getvcpuinfo.cpu = v->processor; ret = 0; copyback = 1; --- a/xen/common/sched/core.c +++ b/xen/common/sched/core.c @@ -325,15 +325,35 @@ void vcpu_runstate_get(const struct vcpu } } -uint64_t get_cpu_idle_time(unsigned int cpu) +uint64_t vcpu_runstate_get_running(const struct vcpu *v) { - struct vcpu_runstate_info state = { 0 }; - const struct vcpu *v = idle_vcpu[cpu]; + struct seqcount seq = SEQCNT_ZERO(); + const struct seqcount *s = v == current ? &seq : &v->runstate_seq; + unsigned int count; + uint64_t running; + s_time_t delta; + + do { + count = read_seqcount_begin(s); + + running = v->runstate.time[RUNSTATE_running]; + delta = v->runstate.state == RUNSTATE_running + ? NOW() - v->runstate.state_entry_time + : 0; + } while ( read_seqcount_retry(s, count) ); + + if ( delta > 0 ) + running += delta; + return running; +} + +uint64_t get_cpu_idle_time(unsigned int cpu) +{ if ( cpu_online(cpu) && get_sched_res(cpu) ) - vcpu_runstate_get(v, &state); + return vcpu_runstate_get_running(idle_vcpu[cpu]); - return state.time[RUNSTATE_running]; + return 0; } /* --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -1121,6 +1121,7 @@ int vcpu_affinity_domctl(struct domain * void vcpu_runstate_get(const struct vcpu *v, struct vcpu_runstate_info *runstate); +uint64_t vcpu_runstate_get_running(const struct vcpu *v); uint64_t get_cpu_idle_time(unsigned int cpu); void sched_guest_idle(void (*idle) (void), unsigned int cpu); void scheduler_enable(void);