From: Sean Christopherson <seanjc@google.com>
To: Wei Wang <wei.w.wang@intel.com>
Cc: pbonzini@redhat.com, dmatlack@google.com, vipinsh@google.com,
ajones@ventanamicro.com, eric.auger@redhat.com,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 03/18] KVM: selftests/kvm_util: helper functions for vcpus and threads
Date: Thu, 27 Oct 2022 00:09:38 +0000 [thread overview]
Message-ID: <Y1nMQp11RKTDX7HX@google.com> (raw)
In-Reply-To: <20221024113445.1022147-4-wei.w.wang@intel.com>
On Mon, Oct 24, 2022, Wei Wang wrote:
> @@ -14,4 +15,23 @@
> for (i = 0, vcpu = vm->vcpus[0]; \
> vcpu && i < KVM_MAX_VCPUS; vcpu = vm->vcpus[++i])
>
> +void __pthread_create_with_name(pthread_t *thread, const pthread_attr_t *attr,
Can these return pthread_t instead of taking them as a param and have a "void"
return? I'm pretty sure pthread_t is an integer type in most implementations,
i.e. can be cheaply copied by value.
> + void *(*start_routine)(void *), void *arg, char *name);
Add a typedef for the payload, both to make it harder to screw up, and to make the
code more readable. Does pthread really not provide one already?
> +void pthread_create_with_name(pthread_t *thread,
> + void *(*start_routine)(void *), void *arg, char *name);
Align params, e.g.
void pthread_create_with_name(pthread_t *thread, void *(*start_routine)(void *),
void *arg, char *name);
Poking out past the 80 char soft limit is much preferable to arbitrary indentation.
Please fix this in all patches.
> struct userspace_mem_regions {
> diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
> index 1f69f5ca8356..ba3e774087fb 100644
> --- a/tools/testing/selftests/kvm/lib/kvm_util.c
> +++ b/tools/testing/selftests/kvm/lib/kvm_util.c
> @@ -2006,3 +2006,175 @@ void __vm_get_stat(struct kvm_vm *vm, const char *stat_name, uint64_t *data,
> break;
> }
> }
> +
> +/*
> + * Create a named thread with user's attribute
> + *
> + * Input Args:
> + * attr - the attribute of the thread to create
> + * start_routine - the routine to run in the thread context
> + * arg - the argument passed to start_routine
> + * name - the name of the thread
> + *
> + * Output Args:
> + * thread - the thread to be created
> + *
> + * Create a thread with a user specified name.
> + */
Please don't add function comments, we're opportunistically removing the existing
boilerplate ones as we go. Most of the comments, like this one, add very little
value as it's pretty obvious what the function does and what the params are.
> +void __pthread_create_with_name(pthread_t *thread, const pthread_attr_t *attr,
> + void *(*start_routine)(void *), void *arg, char *name)
> +{
> + int r;
> +
> + r = pthread_create(thread, NULL, start_routine, arg);
> + TEST_ASSERT(!r, "thread(%s) creation failed, r = %d", name, r);
Assuming 'r' is an errno, pretty print its name with strerror().
> + r = pthread_setname_np(*thread, name);
> + TEST_ASSERT(!r, "thread(%s) setting name failed, r = %d", name, r);
Same here.
> +}
...
> +void vm_vcpu_threads_create(struct kvm_vm *vm,
> + void *(*start_routine)(void *), uint32_t private_data_size)
I vote (very strongly) to not deal with allocating private data. The private data
isn't strictly related to threads, and the vast majority of callers don't need
private data, i.e. the param is dead weight in most cases.
And unless I'm missing something, it's trivial to move to a separate helper,
though honestly even that seems like overkill.
Wait, looking further, it already is a separate helper... Forcing a bunch of
callers to specify '0' just to eliminate one function call in a handful of cases
is not a good tradeoff.
> +void vm_vcpu_threads_private_data_alloc(struct kvm_vm *vm, uint32_t data_size)
As above, this isn't strictly related to threads, e.g. vm_alloc_vcpu_private_data()
> +{
> + struct kvm_vcpu *vcpu;
> + int i;
> +
> + vm_iterate_over_vcpus(vm, vcpu, i) {
> + vcpu->private_data = calloc(1, data_size);
> + TEST_ASSERT(vcpu->private_data, "%s: failed", __func__);
> + }
> +}
> --
> 2.27.0
>
next prev parent reply other threads:[~2022-10-27 0:09 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-24 11:34 [PATCH v1 00/18] KVM selftests code consolidation and cleanup Wei Wang
2022-10-24 11:34 ` [PATCH v1 01/18] KVM: selftests/kvm_util: use array of pointers to maintain vcpus in kvm_vm Wei Wang
2022-10-26 23:47 ` Sean Christopherson
2022-10-27 12:28 ` Wang, Wei W
2022-10-27 15:27 ` Sean Christopherson
2022-10-28 2:13 ` Wang, Wei W
2022-10-24 11:34 ` [PATCH v1 02/18] KVM: selftests/kvm_util: use vm->vcpus[] when create vm with vcpus Wei Wang
2022-10-24 11:34 ` [PATCH v1 03/18] KVM: selftests/kvm_util: helper functions for vcpus and threads Wei Wang
2022-10-27 0:09 ` Sean Christopherson [this message]
2022-10-27 14:02 ` Wang, Wei W
2022-10-27 14:54 ` Sean Christopherson
2022-10-24 11:34 ` [PATCH v1 04/18] KVM: selftests/kvm_page_table_test: vcpu related code consolidation Wei Wang
2022-10-24 11:34 ` [PATCH v1 05/18] KVM: selftests/hardware_disable_test: code consolidation and cleanup Wei Wang
2022-10-27 0:16 ` Sean Christopherson
2022-10-27 14:14 ` Wang, Wei W
2022-10-27 18:03 ` Sean Christopherson
2022-10-28 2:16 ` Wang, Wei W
2022-10-24 11:34 ` [PATCH v1 06/18] KVM: selftests/dirty_log_test: vcpu related code consolidation Wei Wang
2022-10-24 11:34 ` [PATCH v1 07/18] KVM: selftests/max_guest_memory_test: " Wei Wang
2022-10-24 11:34 ` [PATCH v1 08/18] KVM: selftests/set_memory_region_test: " Wei Wang
2022-10-24 11:34 ` [PATCH v1 09/18] KVM: selftests/steal_time: vcpu related code consolidation and cleanup Wei Wang
2022-10-27 0:17 ` Sean Christopherson
2022-10-24 11:34 ` [PATCH v1 10/18] KVM: selftests/tsc_scaling_sync: vcpu related code consolidation Wei Wang
2022-10-24 11:34 ` [PATCH v1 11/18] KVM: selftest/xapic_ipi_test: " Wei Wang
2022-10-24 11:34 ` [PATCH v1 12/18] KVM: selftests/rseq_test: name the migration thread and some cleanup Wei Wang
2022-10-27 0:18 ` Sean Christopherson
2022-10-24 11:34 ` [PATCH v1 13/18] KVM: selftests/perf_test_util: vcpu related code consolidation Wei Wang
2022-10-24 11:34 ` [PATCH v1 14/18] KVM: selftest/memslot_perf_test: " Wei Wang
2022-10-24 11:34 ` [PATCH v1 15/18] KVM: selftests/vgic_init: " Wei Wang
2022-10-24 11:34 ` [PATCH v1 16/18] KVM: selftest/arch_timer: " Wei Wang
2022-10-24 11:34 ` [PATCH v1 17/18] KVM: selftests: remove the *vcpu[] input from __vm_create_with_vcpus Wei Wang
2022-10-24 11:34 ` [PATCH v1 18/18] KVM: selftests/kvm_create_max_vcpus: check KVM_MAX_VCPUS Wei Wang
2022-10-27 0:22 ` Sean Christopherson
2022-10-26 21:22 ` [PATCH v1 00/18] KVM selftests code consolidation and cleanup David Matlack
2022-10-27 12:18 ` Wang, Wei W
2022-10-27 15:44 ` Sean Christopherson
2022-10-27 16:24 ` David Matlack
2022-10-27 18:27 ` Sean Christopherson
2022-10-28 12:41 ` Andrew Jones
2022-10-28 15:49 ` Sean Christopherson
2022-11-07 18:11 ` David Matlack
2022-11-07 18:19 ` Sean Christopherson
2022-11-09 19:05 ` David Matlack
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=Y1nMQp11RKTDX7HX@google.com \
--to=seanjc@google.com \
--cc=ajones@ventanamicro.com \
--cc=dmatlack@google.com \
--cc=eric.auger@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=vipinsh@google.com \
--cc=wei.w.wang@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).