All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ricardo Koller <ricarkol@google.com>
To: Sean Christopherson <seanjc@google.com>
Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu,
	drjones@redhat.com, maz@kernel.org, pbonzini@redhat.com
Subject: Re: [PATCH v3 2/4] KVM: selftests: add is_cpu_online() utility function
Date: Thu, 24 Mar 2022 10:29:35 -0700	[thread overview]
Message-ID: <Yjyqf5oAxZzC7g7H@google.com> (raw)
In-Reply-To: <YjyoJu0/Saowtrbc@google.com>

On Thu, Mar 24, 2022 at 05:19:34PM +0000, Sean Christopherson wrote:
> On Tue, Mar 22, 2022, Ricardo Koller wrote:
> > Add is_cpu_online() utility function: a wrapper for
> > "/sys/devices/system/cpu/cpu%d/online".
> > 
> > Signed-off-by: Ricardo Koller <ricarkol@google.com>
> > ---
> >  tools/testing/selftests/kvm/include/test_util.h |  2 ++
> >  tools/testing/selftests/kvm/lib/test_util.c     | 16 ++++++++++++++++
> >  2 files changed, 18 insertions(+)
> > 
> > diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing/selftests/kvm/include/test_util.h
> > index 99e0dcdc923f..14084dc4e152 100644
> > --- a/tools/testing/selftests/kvm/include/test_util.h
> > +++ b/tools/testing/selftests/kvm/include/test_util.h
> > @@ -143,4 +143,6 @@ static inline void *align_ptr_up(void *x, size_t size)
> >  	return (void *)align_up((unsigned long)x, size);
> >  }
> >  
> > +bool is_cpu_online(int pcpu);
> > +
> >  #endif /* SELFTEST_KVM_TEST_UTIL_H */
> > diff --git a/tools/testing/selftests/kvm/lib/test_util.c b/tools/testing/selftests/kvm/lib/test_util.c
> > index 6d23878bbfe1..81950e6b6d10 100644
> > --- a/tools/testing/selftests/kvm/lib/test_util.c
> > +++ b/tools/testing/selftests/kvm/lib/test_util.c
> > @@ -334,3 +334,19 @@ long get_run_delay(void)
> >  
> >  	return val[1];
> >  }
> > +
> > +bool is_cpu_online(int pcpu)
> > +{
> > +	char p[128];
> > +	FILE *fp;
> > +	int ret;
> > +
> > +	snprintf(p, sizeof(p), "/sys/devices/system/cpu/cpu%d/online", pcpu);
> 
> I don't think this is sufficient for the use in patch 03; the CPU could be online
> but disallowed for use by the current task.  I think what you want instead is a
> combination of get_nprocs_conf() + sched_getaffinity() + CPU_ISSET().

Good point. I was just thinking about the more common situation where a
user tries to use a CPU that doesn't even exist. Will fix in v4.

Thanks,
Ricardo

WARNING: multiple messages have this Message-ID (diff)
From: Ricardo Koller <ricarkol@google.com>
To: Sean Christopherson <seanjc@google.com>
Cc: maz@kernel.org, kvmarm@lists.cs.columbia.edu,
	kvm@vger.kernel.org, pbonzini@redhat.com
Subject: Re: [PATCH v3 2/4] KVM: selftests: add is_cpu_online() utility function
Date: Thu, 24 Mar 2022 10:29:35 -0700	[thread overview]
Message-ID: <Yjyqf5oAxZzC7g7H@google.com> (raw)
In-Reply-To: <YjyoJu0/Saowtrbc@google.com>

On Thu, Mar 24, 2022 at 05:19:34PM +0000, Sean Christopherson wrote:
> On Tue, Mar 22, 2022, Ricardo Koller wrote:
> > Add is_cpu_online() utility function: a wrapper for
> > "/sys/devices/system/cpu/cpu%d/online".
> > 
> > Signed-off-by: Ricardo Koller <ricarkol@google.com>
> > ---
> >  tools/testing/selftests/kvm/include/test_util.h |  2 ++
> >  tools/testing/selftests/kvm/lib/test_util.c     | 16 ++++++++++++++++
> >  2 files changed, 18 insertions(+)
> > 
> > diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing/selftests/kvm/include/test_util.h
> > index 99e0dcdc923f..14084dc4e152 100644
> > --- a/tools/testing/selftests/kvm/include/test_util.h
> > +++ b/tools/testing/selftests/kvm/include/test_util.h
> > @@ -143,4 +143,6 @@ static inline void *align_ptr_up(void *x, size_t size)
> >  	return (void *)align_up((unsigned long)x, size);
> >  }
> >  
> > +bool is_cpu_online(int pcpu);
> > +
> >  #endif /* SELFTEST_KVM_TEST_UTIL_H */
> > diff --git a/tools/testing/selftests/kvm/lib/test_util.c b/tools/testing/selftests/kvm/lib/test_util.c
> > index 6d23878bbfe1..81950e6b6d10 100644
> > --- a/tools/testing/selftests/kvm/lib/test_util.c
> > +++ b/tools/testing/selftests/kvm/lib/test_util.c
> > @@ -334,3 +334,19 @@ long get_run_delay(void)
> >  
> >  	return val[1];
> >  }
> > +
> > +bool is_cpu_online(int pcpu)
> > +{
> > +	char p[128];
> > +	FILE *fp;
> > +	int ret;
> > +
> > +	snprintf(p, sizeof(p), "/sys/devices/system/cpu/cpu%d/online", pcpu);
> 
> I don't think this is sufficient for the use in patch 03; the CPU could be online
> but disallowed for use by the current task.  I think what you want instead is a
> combination of get_nprocs_conf() + sched_getaffinity() + CPU_ISSET().

Good point. I was just thinking about the more common situation where a
user tries to use a CPU that doesn't even exist. Will fix in v4.

Thanks,
Ricardo
_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

  reply	other threads:[~2022-03-24 17:29 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-22 17:23 [PATCH v3 0/4] KVM: arm64: selftests: Add edge cases tests for the arch timer Ricardo Koller
2022-03-22 17:23 ` Ricardo Koller
2022-03-22 17:23 ` [PATCH v3 1/4] KVM: arm64: selftests: add timer_get_tval() lib function Ricardo Koller
2022-03-22 17:23   ` Ricardo Koller
2022-03-22 17:23 ` [PATCH v3 2/4] KVM: selftests: add is_cpu_online() utility function Ricardo Koller
2022-03-22 17:23   ` Ricardo Koller
2022-03-24 17:19   ` Sean Christopherson
2022-03-24 17:19     ` Sean Christopherson
2022-03-24 17:29     ` Ricardo Koller [this message]
2022-03-24 17:29       ` Ricardo Koller
2022-03-22 17:23 ` [PATCH v3 3/4] KVM: arm64: selftests: add arch_timer_edge_cases Ricardo Koller
2022-03-22 17:23   ` Ricardo Koller
2022-03-22 17:23 ` [PATCH v3 4/4] KVM: arm64: selftests: add edge cases tests into arch_timer_edge_cases Ricardo Koller
2022-03-22 17:23   ` Ricardo Koller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Yjyqf5oAxZzC7g7H@google.com \
    --to=ricarkol@google.com \
    --cc=drjones@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=maz@kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.