From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36A3DC433E0 for ; Tue, 26 May 2020 11:20:25 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CF9342053B for ; Tue, 26 May 2020 11:20:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="XiAZi2TO"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="XiAZi2TO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CF9342053B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 49WWj22GnvzDqBt for ; Tue, 26 May 2020 21:20:22 +1000 (AEST) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=redhat.com (client-ip=207.211.31.81; helo=us-smtp-delivery-1.mimecast.com; envelope-from=eesposit@redhat.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=XiAZi2TO; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=XiAZi2TO; dkim-atps=neutral Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 49WWN26SFWzDqLD for ; Tue, 26 May 2020 21:05:38 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590491135; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Wxo/6JU4Ay6RfuSzG9nMM1AaC69gbyAXb63u8KjD7Xg=; b=XiAZi2TOZDZJmhIxi2K0DzmBtb0TxWtlVH28tlcD/A7o6qGwqihzmcz7SF4yyJ14YwwFnI Kw6dLnFrgx3dppVWkttUbhN15rmc+t58J8iCqEciH41jdSFzSV5CrPbngH0LtJIRblzsSm 9NOVBsjlPy82agfwwH120fpSExQOdcM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590491135; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Wxo/6JU4Ay6RfuSzG9nMM1AaC69gbyAXb63u8KjD7Xg=; b=XiAZi2TOZDZJmhIxi2K0DzmBtb0TxWtlVH28tlcD/A7o6qGwqihzmcz7SF4yyJ14YwwFnI Kw6dLnFrgx3dppVWkttUbhN15rmc+t58J8iCqEciH41jdSFzSV5CrPbngH0LtJIRblzsSm 9NOVBsjlPy82agfwwH120fpSExQOdcM= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-73-oxEJJBr4OkK1dAESxlCq4Q-1; Tue, 26 May 2020 07:05:33 -0400 X-MC-Unique: oxEJJBr4OkK1dAESxlCq4Q-1 Received: by mail-wr1-f72.google.com with SMTP id h6so8834083wrx.4 for ; Tue, 26 May 2020 04:05:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Wxo/6JU4Ay6RfuSzG9nMM1AaC69gbyAXb63u8KjD7Xg=; b=rlXOXqdLBRh+OdMp/J4+LilbCzS3e+Q2MaLIVQBNx/UkubDRUNw7ekdHjehx9+ypGS pPMjFJGGXGETUJU1UGmse2iBTyCZfv3cFgN+oMIdDVPfCZkTh/ZWU0CSr0O2JWs3OmpB HZ++2cU26XBmEn/2Cdzk3VG+vcKeMe5fpBUdcCtHne9nciPkVnyHIIemS2En/80X6aru OOAm3gAQLBc4Cx9T7AgnsnXKof092m4m2kRg9j7zK0FqcqZo8j8+lcfNLZzARe5n0B/3 8mjEZ8+sPK+iolBYEIsGXFAkCvd+BZOZnOBrFgETUkJn3+Rgsp9cvEHR7Hxv/OtLfTaW 9ZuQ== X-Gm-Message-State: AOAM532nEa5pGHuS+kb59uCOQOxP02eIysDD+8UhlPgYpZa50jv6ILpa r4ixEbFFp4rbHIqhEjE9ttnNeZz3mZtTZI1DIqKEdaIxItcwF02VdvD8nxYA0Awcjmui5O9BKMH LdIQMfhGftTzI5ym9kXDeCD80Bg== X-Received: by 2002:adf:a41a:: with SMTP id d26mr3564295wra.324.1590491132508; Tue, 26 May 2020 04:05:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtQPejIzuIOGlk59w68WJzfZKAuFRIeGqcFi7BVaubrvbOSzWLRRAG5Ol3GCpsl8mHBwP8Og== X-Received: by 2002:adf:a41a:: with SMTP id d26mr3564265wra.324.1590491132283; Tue, 26 May 2020 04:05:32 -0700 (PDT) Received: from localhost.localdomain.com ([194.230.155.118]) by smtp.gmail.com with ESMTPSA id d6sm22928240wrj.90.2020.05.26.04.05.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 May 2020 04:05:23 -0700 (PDT) From: Emanuele Giuseppe Esposito To: kvm@vger.kernel.org Subject: [PATCH v3 6/7] [not for merge] kvm: example of stats_fs_value show function Date: Tue, 26 May 2020 13:03:16 +0200 Message-Id: <20200526110318.69006-7-eesposit@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200526110318.69006-1-eesposit@redhat.com> References: <20200526110318.69006-1-eesposit@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 8bit X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Emanuele Giuseppe Esposito , linux-s390@vger.kernel.org, linux-doc@vger.kernel.org, netdev@vger.kernel.org, Emanuele Giuseppe Esposito , linux-kernel@vger.kernel.org, kvm-ppc@vger.kernel.org, Jonathan Adams , Christian Borntraeger , Alexander Viro , David Rientjes , linux-fsdevel@vger.kernel.org, Paolo Bonzini , linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, Jim Mattson Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" Add an example of the show function using the mp_state value. mp_state is an enum that represents the VCPU state, so instead of displaying its integer representation, the show function takes care of translating the integer into a more meaningful string representation. The VCPU status is shown in the kvm//vcpu/mp_state file Signed-off-by: Emanuele Giuseppe Esposito --- arch/x86/kvm/stats_fs.c | 54 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/arch/x86/kvm/stats_fs.c b/arch/x86/kvm/stats_fs.c index f6edebb9c559..902be18562da 100644 --- a/arch/x86/kvm/stats_fs.c +++ b/arch/x86/kvm/stats_fs.c @@ -39,11 +39,65 @@ struct stats_fs_value stats_fs_vcpu_arch_tsc_frac[] = { { NULL } /* base is &kvm_tsc_scaling_ratio_frac_bits */ }; +char *stats_fs_vcpu_get_mpstate(uint64_t state) +{ + char *state_str; + + state_str = kzalloc(20, GFP_KERNEL); + if (!state_str) + return ERR_PTR(-ENOMEM); + + switch (state) { + case KVM_MP_STATE_RUNNABLE: + strcpy(state_str, "RUNNABLE"); + break; + case KVM_MP_STATE_UNINITIALIZED: + strcpy(state_str, "UNINITIALIZED"); + break; + case KVM_MP_STATE_INIT_RECEIVED: + strcpy(state_str, "INIT_RECEIVED"); + break; + case KVM_MP_STATE_HALTED: + strcpy(state_str, "HALTED"); + break; + case KVM_MP_STATE_SIPI_RECEIVED: + strcpy(state_str, "SIPI_RECEIVED"); + break; + case KVM_MP_STATE_STOPPED: + strcpy(state_str, "STOPPED"); + break; + case KVM_MP_STATE_CHECK_STOP: + strcpy(state_str, "CHECK_STOP"); + break; + case KVM_MP_STATE_OPERATING: + strcpy(state_str, "OPERATING"); + break; + case KVM_MP_STATE_LOAD: + strcpy(state_str, "LOAD"); + break; + default: + strcpy(state_str, "UNRECOGNIZED"); + break; + } + + return state_str; +} + +struct stats_fs_value stats_fs_vcpu_mp_state[] = { + VCPU_ARCH_STATS_FS("mp_state", kvm_vcpu_arch, mp_state, + .type = &stats_fs_type_u32, + .show = stats_fs_vcpu_get_mpstate), + { NULL } +}; + void kvm_arch_create_vcpu_stats_fs(struct kvm_vcpu *vcpu) { stats_fs_source_add_values(vcpu->stats_fs_src, stats_fs_vcpu_tsc_offset, &vcpu->arch, 0); + stats_fs_source_add_values(vcpu->stats_fs_src, stats_fs_vcpu_mp_state, + &vcpu->arch, 0); + if (lapic_in_kernel(vcpu)) stats_fs_source_add_values(vcpu->stats_fs_src, stats_fs_vcpu_arch_lapic_timer, -- 2.25.4