[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH for-4.22? 1/9] sched: introduce specialization of "running only" vcpu_runstate_get()


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Tue, 16 Jun 2026 10:41:00 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=h9rDnPCnH3MHgCBZIVdkyEmzw7QXfupbZyecdorN3Zo=; b=tUs6XO3X6WIq8sVYr+fZe0ZyHF0IPKwX1BQYbhnxhEWengNTkLM/P0afOP36ypDnxKMXHCgd3B0vtrVUSk+QgIySrgt4I9P7VotFK8L7BiM2C49Y6BO6+I9Oo9akQwxd5StM+5faPDTPHRzXZSMhT8LD5Ph3UW2Uq8Fg2bW90c0Ezxc2Gp/dYgXqA1nGLkZJ3eROHfyVZGH1+9br53FyJehayoPF2LmFIB0dPrrLt0eHNEAn9UM/WMc8/8FZSdZx6cBt8s+erO6JWUw9OmluqQKQwAxFAn3iWe8RpOMc08HPizLkd7yoUacDh0dcEi94jjEHhKMZJsnlXxENyGDvEw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=pe9z95IpGyK0B33D09M2c7K+GFPZPDZPYa6VnZ79EzbAb2t/+5CFSR4To9wkxX2pgq0XkCLJ8EfBZneRg2ui0rLzYdzuEqK9hHJuoQJs0XcKfIrf9rEuRnjSBb0+olTJIcWBlHCARRWjAbA9PNBNR73eWGeHLBNdieh/GYOH6einehJG69HwCaqSlAr+g0CYr/u+9ubCmo5THy7Uoi3r4avyY5P4L9FFeVqRBgYVAiLSdmYXT40ls2CLI7R+E6ghW3b9JUqQ11t8RXIKbNTX58pK8dFspjFhvVeYnEZZymzrq6VJxYK4GYdxqulHQx6TTBqgodWvne6Q+XVV8aoo7g==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=citrix.com header.i="@citrix.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>, Dario Faggioli <dfaggioli@xxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, George Dunlap <gwd@xxxxxxxxxxxxxx>
  • Delivery-date: Tue, 16 Jun 2026 08:41:10 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Mon, Jun 15, 2026 at 04:12:11PM +0200, Jan Beulich wrote:
> 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 <jbeulich@xxxxxxxx>

Acked-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>

> ---
> 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().

FWIW, I think the fact that you can find call sites by using
vcpu_runstate_get is likely to become irrelevant in the long run.

> 
> --- 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) )
>          {
> @@ -829,8 +827,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 )
> @@ -840,12 +837,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;

Does it make a difference to use a local fake sequence counter or the
real one if the vCPU is the one currently running in this pCPU?  If
it's the running vCPU then it won't get the counters updated, and
hence using the real or a fake counter won't matter, as it will never
be updated while carrying out the read.  IOW: the usage of a local
sequence counter for that specific case just adds more logic without a
real benefit?

Thanks, Roger.



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.