All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oliver Upton <oupton@google.com>
To: Ricardo Koller <ricarkol@google.com>
Cc: kvm@vger.kernel.org, maz@kernel.org, pbonzini@redhat.com,
	kvmarm@lists.cs.columbia.edu
Subject: Re: [PATCH v4 2/4] KVM: selftests: add is_cpu_eligible_to_run() utility function
Date: Tue, 5 Apr 2022 00:13:33 +0000	[thread overview]
Message-ID: <YkuJrYL6wL5P5JY/@google.com> (raw)
In-Reply-To: <20220404214642.3201659-3-ricarkol@google.com>

Hi Ricardo,

On Mon, Apr 04, 2022 at 02:46:40PM -0700, Ricardo Koller wrote:
> Add is_cpu_eligible_to_run() utility function, which checks whether the current
> process, or one of its threads, is eligible to run on a particular CPU.
> This information is obtained using sched_getaffinity.
> 
> Signed-off-by: Ricardo Koller <ricarkol@google.com>
> ---
>  .../testing/selftests/kvm/include/test_util.h |  2 ++
>  tools/testing/selftests/kvm/lib/test_util.c   | 20 ++++++++++++++++++-
>  2 files changed, 21 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing/selftests/kvm/include/test_util.h
> index 99e0dcdc923f..a7653f369b6c 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_eligible_to_run(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..7813a68333c0 100644
> --- a/tools/testing/selftests/kvm/lib/test_util.c
> +++ b/tools/testing/selftests/kvm/lib/test_util.c
> @@ -4,6 +4,7 @@
>   *
>   * Copyright (C) 2020, Google LLC.
>   */
> +#define _GNU_SOURCE
>  
>  #include <assert.h>
>  #include <ctype.h>
> @@ -13,7 +14,9 @@
>  #include <sys/stat.h>
>  #include <sys/syscall.h>
>  #include <linux/mman.h>
> -#include "linux/kernel.h"
> +#include <linux/kernel.h>
> +#include <sched.h>
> +#include <sys/sysinfo.h>
>  
>  #include "test_util.h"
>  
> @@ -334,3 +337,18 @@ long get_run_delay(void)
>  
>  	return val[1];
>  }
> +
> +bool is_cpu_eligible_to_run(int pcpu)
> +{
> +	cpu_set_t cpuset;
> +	long i, nprocs;
> +
> +	nprocs = get_nprocs_conf();
> +	sched_getaffinity(0, sizeof(cpu_set_t), &cpuset);
> +	for (i = 0; i < nprocs; i++) {
> +		if (i == pcpu)
> +			return CPU_ISSET(i, &cpuset);
> +	}

I don't think you need the loop and can just do CPU_ISSET(pcpu, &cpuset),
right?

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

WARNING: multiple messages have this Message-ID (diff)
From: Oliver Upton <oupton@google.com>
To: Ricardo Koller <ricarkol@google.com>
Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu,
	drjones@redhat.com, pbonzini@redhat.com, maz@kernel.org,
	alexandru.elisei@arm.com, eric.auger@redhat.com,
	reijiw@google.com, rananta@google.com
Subject: Re: [PATCH v4 2/4] KVM: selftests: add is_cpu_eligible_to_run() utility function
Date: Tue, 5 Apr 2022 00:13:33 +0000	[thread overview]
Message-ID: <YkuJrYL6wL5P5JY/@google.com> (raw)
In-Reply-To: <20220404214642.3201659-3-ricarkol@google.com>

Hi Ricardo,

On Mon, Apr 04, 2022 at 02:46:40PM -0700, Ricardo Koller wrote:
> Add is_cpu_eligible_to_run() utility function, which checks whether the current
> process, or one of its threads, is eligible to run on a particular CPU.
> This information is obtained using sched_getaffinity.
> 
> Signed-off-by: Ricardo Koller <ricarkol@google.com>
> ---
>  .../testing/selftests/kvm/include/test_util.h |  2 ++
>  tools/testing/selftests/kvm/lib/test_util.c   | 20 ++++++++++++++++++-
>  2 files changed, 21 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing/selftests/kvm/include/test_util.h
> index 99e0dcdc923f..a7653f369b6c 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_eligible_to_run(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..7813a68333c0 100644
> --- a/tools/testing/selftests/kvm/lib/test_util.c
> +++ b/tools/testing/selftests/kvm/lib/test_util.c
> @@ -4,6 +4,7 @@
>   *
>   * Copyright (C) 2020, Google LLC.
>   */
> +#define _GNU_SOURCE
>  
>  #include <assert.h>
>  #include <ctype.h>
> @@ -13,7 +14,9 @@
>  #include <sys/stat.h>
>  #include <sys/syscall.h>
>  #include <linux/mman.h>
> -#include "linux/kernel.h"
> +#include <linux/kernel.h>
> +#include <sched.h>
> +#include <sys/sysinfo.h>
>  
>  #include "test_util.h"
>  
> @@ -334,3 +337,18 @@ long get_run_delay(void)
>  
>  	return val[1];
>  }
> +
> +bool is_cpu_eligible_to_run(int pcpu)
> +{
> +	cpu_set_t cpuset;
> +	long i, nprocs;
> +
> +	nprocs = get_nprocs_conf();
> +	sched_getaffinity(0, sizeof(cpu_set_t), &cpuset);
> +	for (i = 0; i < nprocs; i++) {
> +		if (i == pcpu)
> +			return CPU_ISSET(i, &cpuset);
> +	}

I don't think you need the loop and can just do CPU_ISSET(pcpu, &cpuset),
right?

--
Thanks,
Oliver

  reply	other threads:[~2022-04-05  0:13 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-04 21:46 [PATCH v4 0/4] KVM: arm64: selftests: Add edge cases tests for the arch timer Ricardo Koller
2022-04-04 21:46 ` Ricardo Koller
2022-04-04 21:46 ` [PATCH v4 1/4] KVM: arm64: selftests: add timer_get_tval() lib function Ricardo Koller
2022-04-04 21:46   ` Ricardo Koller
2022-04-04 21:46 ` [PATCH v4 2/4] KVM: selftests: add is_cpu_eligible_to_run() utility function Ricardo Koller
2022-04-04 21:46   ` Ricardo Koller
2022-04-05  0:13   ` Oliver Upton [this message]
2022-04-05  0:13     ` Oliver Upton
2022-04-05  1:56     ` Ricardo Koller
2022-04-05  1:56       ` Ricardo Koller
2022-04-04 21:46 ` [PATCH v4 3/4] KVM: arm64: selftests: add arch_timer_edge_cases Ricardo Koller
2022-04-04 21:46   ` Ricardo Koller
2022-04-04 21:46 ` [PATCH v4 4/4] KVM: arm64: selftests: add edge cases tests into arch_timer_edge_cases Ricardo Koller
2022-04-04 21:46   ` 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=YkuJrYL6wL5P5JY/@google.com \
    --to=oupton@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=maz@kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=ricarkol@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.