Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp531141pxb; Thu, 9 Sep 2021 06:33:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzaaiijT73SEhzocuqpLQY3s/eCRzf01J/3mX84GPOAPtE5YWZ0ybkG7AiWOXYD0cIh/t2d X-Received: by 2002:a05:6e02:1aa2:: with SMTP id l2mr2358252ilv.168.1631194396117; Thu, 09 Sep 2021 06:33:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631194396; cv=none; d=google.com; s=arc-20160816; b=NvY+20bIVPs6jABOxvch10rTnzNzDCTlKqTnXWDzLdbAl1fp2GLUMJIf9GzyOMJbhP fbtCIj0gmGkClavLxJ4waDsafYv3xEHYOKwSCNRCDXzo/wtlP7sYHK62FjTZdh6gR6c2 gsAk8wwPTTbd+rYvN+rB7GnzvvzR/ZWiVpZgvz6h8MRJ0VNJlBSo6Pni9mrHz3JLQQKp vZcFuWQeDuucfNw2e5R33hH6CS3S3F1+v/7RZIPvsZSwcyU+HJJ7NFAbjaeUSLioMZEZ osNF8VzEHkEGow6vTqkopsdtKkGLhnZxxMrSDoshTqGJSks5h1FjaswN3JOVSxJbuCYF C5bQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=IPz8rCaG1n5gmzRfNCxWNsl8VhshhGe4oboIWdB5nfY=; b=nRIYHVnNdK5ztJMcPJSsQMVAoctkHjrclgwHgvT7eStO90fPYs2mh0d3xy5Aw7b5go YOoH6XxEs7pGpNM+O2bPONCStsj52KG4qHZ96bleth71EZ+fgWhi2O2mgOdRCFTJgkcP KxD00F+4VMm7DFG665My3MrrS0+C04C0WJgJOunqIdBU3SYT0kVp4/DgVScZCFktAckU R0dXhLoO9yKiIWL2cS+aIAAusvMTcleveXB3lOqpt+o6gV1UQ7kLhEiI7+Yc4tjs+Nzb dmVoLvnNM3uHVBJUMvzm6SQN3La2ZNUpwEue/7GAPtsmBP3Y7+7mH2DNk6o6U0wA5FX6 uTTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KSZCZ0hk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u13si2227307jak.109.2021.09.09.06.33.04; Thu, 09 Sep 2021 06:33:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KSZCZ0hk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356890AbhIINdV (ORCPT + 99 others); Thu, 9 Sep 2021 09:33:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:24124 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355378AbhIINVf (ORCPT ); Thu, 9 Sep 2021 09:21:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631193624; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=IPz8rCaG1n5gmzRfNCxWNsl8VhshhGe4oboIWdB5nfY=; b=KSZCZ0hko8hs84noG+nqXvOscbfUG75oiireZPmg2dNDLY2HcvscyJlnnCLOGcWb9gmxt8 +jGq6lib6Yu4r8aGoxvL2fk7ykm5n9mhcWBNNMFDQDJrqhf2NvVtlPBAY231jrTCRhTYqG WmqD6VGuu3j7TBG0ty6k0YoYW4yTMlc= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-355-i7AIqjliMJ6Wxgc9vQyBxQ-1; Thu, 09 Sep 2021 09:20:23 -0400 X-MC-Unique: i7AIqjliMJ6Wxgc9vQyBxQ-1 Received: by mail-ed1-f72.google.com with SMTP id m30-20020a50999e000000b003cdd7680c8cso954752edb.11 for ; Thu, 09 Sep 2021 06:20:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=IPz8rCaG1n5gmzRfNCxWNsl8VhshhGe4oboIWdB5nfY=; b=sUq5Y1CSKC1Xar1DqjR9cYIH8D7S2YJGfLR8CzIjc1dJolL7m6Mz/MHoFltyc84MW7 DKFQGeYX+Ifc7jLX9w+my3PrAugHdAioHgnIbLj4nRPx7I0Y3ycj/7I0XfGJwp8KRFS8 qSeCJ9vBR20OKMMZG53//g7WNFb9X2eA6wjx6A+lE6ZzhiNyh+6W+jiK2fk4dUh+Ob5v q38PelLMzf65lo64IPQvXJl7vcRmP5aWZDOZ8l3yiI2RJZlwgURot3T2X4tRPu/FiGcD WpCgpDrpHBYjBow4zdUUob8pWWF+lb1iu1plrYoXW54tiD4Nvq4sNDgyxVJXHA7AlbqP iDSg== X-Gm-Message-State: AOAM532aWRLwr1wikusX+o9V+nbnvRTVcrXRAtGMvRMLAVYvnCVXwB4f Rg51F2VCazIR3GBsuO/NFKvdeYxGGb/qdc+bPwr4f+34XUYMvssOGM5ZQNHZXI8tz7Jv+b55Rl4 +anrEeg1XJmGvHBQY2F4NQG/9 X-Received: by 2002:a17:906:1510:: with SMTP id b16mr3523481ejd.332.1631193622101; Thu, 09 Sep 2021 06:20:22 -0700 (PDT) X-Received: by 2002:a17:906:1510:: with SMTP id b16mr3523459ejd.332.1631193621929; Thu, 09 Sep 2021 06:20:21 -0700 (PDT) Received: from gator (cst2-174-132.cust.vodafone.cz. [31.30.174.132]) by smtp.gmail.com with ESMTPSA id l16sm999043eje.67.2021.09.09.06.20.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Sep 2021 06:20:21 -0700 (PDT) Date: Thu, 9 Sep 2021 15:20:19 +0200 From: Andrew Jones To: Raghavendra Rao Ananta Cc: Paolo Bonzini , Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Oliver Upton , Reiji Watanabe , Jing Zhang , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: Re: [PATCH v4 12/18] KVM: selftests: Keep track of the number of vCPUs for a VM Message-ID: <20210909132019.etrlz2t7pes7bc2o@gator> References: <20210909013818.1191270-1-rananta@google.com> <20210909013818.1191270-13-rananta@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210909013818.1191270-13-rananta@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 09, 2021 at 01:38:12AM +0000, Raghavendra Rao Ananta wrote: > The host may want to know the number of vCPUs that were > created for a particular VM (used in upcoming patches). > Hence, include nr_vcpus as a part of 'struct kvm_vm' to > keep track of vCPUs as and when they are added or > deleted, and return to the caller via vm_get_nr_vcpus(). > > Signed-off-by: Raghavendra Rao Ananta > --- > tools/testing/selftests/kvm/include/kvm_util.h | 1 + > tools/testing/selftests/kvm/lib/kvm_util.c | 7 +++++++ > tools/testing/selftests/kvm/lib/kvm_util_internal.h | 1 + > 3 files changed, 9 insertions(+) > > diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h > index 010b59b13917..d5d0ca919928 100644 > --- a/tools/testing/selftests/kvm/include/kvm_util.h > +++ b/tools/testing/selftests/kvm/include/kvm_util.h > @@ -399,5 +399,6 @@ uint64_t get_ucall(struct kvm_vm *vm, uint32_t vcpu_id, struct ucall *uc); > > int vm_get_stats_fd(struct kvm_vm *vm); > int vcpu_get_stats_fd(struct kvm_vm *vm, uint32_t vcpuid); > +int vm_get_nr_vcpus(struct kvm_vm *vm); > > #endif /* SELFTEST_KVM_UTIL_H */ > diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c > index 10a8ed691c66..1b5349b5132f 100644 > --- a/tools/testing/selftests/kvm/lib/kvm_util.c > +++ b/tools/testing/selftests/kvm/lib/kvm_util.c > @@ -594,6 +594,7 @@ static void vm_vcpu_rm(struct kvm_vm *vm, struct vcpu *vcpu) > > list_del(&vcpu->list); > free(vcpu); > + vm->nr_vcpus--; > } > > void kvm_vm_release(struct kvm_vm *vmp) > @@ -1143,6 +1144,7 @@ void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid) > > /* Add to linked-list of VCPUs. */ > list_add(&vcpu->list, &vm->vcpus); > + vm->nr_vcpus++; > } > > /* > @@ -2343,3 +2345,8 @@ int vcpu_get_stats_fd(struct kvm_vm *vm, uint32_t vcpuid) > > return ioctl(vcpu->fd, KVM_GET_STATS_FD, NULL); > } > + > +int vm_get_nr_vcpus(struct kvm_vm *vm) > +{ > + return vm->nr_vcpus; > +} nr_vcpus looks like useful library internal information, since the only other way to get the number is to iterate the vcpu list. I'm not sure if we need this vm_get_nr_vcpus() accessor for tests yet though. Maybe it'll be more clear to me when I see how it's used. Thanks, drew > diff --git a/tools/testing/selftests/kvm/lib/kvm_util_internal.h b/tools/testing/selftests/kvm/lib/kvm_util_internal.h > index a03febc24ba6..be4d852d2f3b 100644 > --- a/tools/testing/selftests/kvm/lib/kvm_util_internal.h > +++ b/tools/testing/selftests/kvm/lib/kvm_util_internal.h > @@ -56,6 +56,7 @@ struct kvm_vm { > unsigned int va_bits; > uint64_t max_gfn; > struct list_head vcpus; > + int nr_vcpus; > struct userspace_mem_regions regions; > struct sparsebit *vpages_valid; > struct sparsebit *vpages_mapped; > -- > 2.33.0.153.gba50c8fa24-goog >