From patchwork Mon Mar 8 21:02:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 12123409 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 8C952C433DB for ; Mon, 8 Mar 2021 21:03:15 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 55927652B2 for ; Mon, 8 Mar 2021 21:03:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 55927652B2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.95095.179460 (Exim 4.92) (envelope-from ) id 1lJN1x-00073i-1k; Mon, 08 Mar 2021 21:03:09 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 95095.179460; Mon, 08 Mar 2021 21:03:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lJN1w-00073W-Tq; Mon, 08 Mar 2021 21:03:08 +0000 Received: by outflank-mailman (input) for mailman id 95095; Mon, 08 Mar 2021 21:03:07 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lJN1v-0006P0-Ja for xen-devel@lists.xenproject.org; Mon, 08 Mar 2021 21:03:07 +0000 Received: from mail-qk1-x734.google.com (unknown [2607:f8b0:4864:20::734]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 29c4ded8-0d52-4eb0-bfdd-c476ea12c676; Mon, 08 Mar 2021 21:02:41 +0000 (UTC) Received: by mail-qk1-x734.google.com with SMTP id n79so10866761qke.3 for ; Mon, 08 Mar 2021 13:02:41 -0800 (PST) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:a33e:daa7:46a1:a7eb]) by smtp.gmail.com with ESMTPSA id r2sm8514070qti.4.2021.03.08.13.02.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 13:02:40 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 29c4ded8-0d52-4eb0-bfdd-c476ea12c676 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oqpttayW0aZRbW0lV0dPSojE1v4QDHZLq85y9vWsmqg=; b=UGXM5D94i40l2yF+567mUWT4APPSKuPbrSXJMkZg5BuwjlTOivLZV1fz9bTrNSSvgG Y8V2o1+yEKAer5QYuFyKFlNTGr6vF0XNtjWCpUvFED2sKYG8aeGFnd3sM7HVzlsHeLFe oJ8ianhNT27nrsSspcoW72aLFh8qeMG9LRK0szHmMUFoX3+Lq/GmY2yXQabpXvitgLzd LE0qBvkIcivh+TrHpbIXFCkNYViEraua5Z8FFMUBuBkC/CT08KmY3rq9AQwBHsCfSoAv 23IoIAimOcZBvsS7CGM86b6Y1A3tJmcQwA44/b9KkQLXSBYonkp3glBlzJx0V+ni6TZw Q5rg== 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=oqpttayW0aZRbW0lV0dPSojE1v4QDHZLq85y9vWsmqg=; b=EmDn2PmUx9+2q0ssbdSrpQb5SxkaEdnZriJWF97yXKz6Gi1biHXdMmZJYzLTjdafgz V0csgLAeQ5+eVOHzN4zTz4P3GErMkmC4kvXIrIdUHYC0WBsMJ8R1wCrThipEXD4dF1zt IzjNiNt102/NOh2AL/fqeU9Gc6GMHXgpi3JAOCLRls6fZxY7qowblMRretyEQmqL0atF wMpp3Qi5wtQo5XfxLyUMgVHavpt71vupuGIDriMcK+gWQSbAcLjFMQxlLXCz/xrxmeJ6 /7fXRB3s34apV//ZX/WIMEJBMs1cFmF9XUdJHamzvfElTTxnM3MlC6wCFXheE5vgdk6u ELPQ== X-Gm-Message-State: AOAM530SL2IdIjD4x/h/z+26AhcEwTt7g0/hw1Left7cn3DFRohrBInt yPNdn6t83HA8QKjpHhPew11iT2hFDhE= X-Google-Smtp-Source: ABdhPJyqwDLmfPxTONGiGVA9Gikx8JwFOaXo2DpQOeXb59DhjVX/AiDXt98uOkdo6jfnCJ6vkD0SzA== X-Received: by 2002:a37:a8cd:: with SMTP id r196mr21870295qke.451.1615237361005; Mon, 08 Mar 2021 13:02:41 -0800 (PST) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: pawel@invisiblethingslab.com, marmarek@invisiblethingslab.com, Jason Andryuk , Ian Jackson , Wei Liu Subject: [RFC 09/12] xenpm: Factor out a non-fatal cpuid_parse variant Date: Mon, 8 Mar 2021 16:02:07 -0500 Message-Id: <20210308210210.116278-10-jandryuk@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210308210210.116278-1-jandryuk@gmail.com> References: <20210308210210.116278-1-jandryuk@gmail.com> MIME-Version: 1.0 Allow cpuid_prase to be re-used without terminating xenpm. HWP will re-use it to optionally parse a cpuid. Signed-off-by: Jason Andryuk --- tools/misc/xenpm.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c index 9588dac991..a686f8f46e 100644 --- a/tools/misc/xenpm.c +++ b/tools/misc/xenpm.c @@ -79,17 +79,26 @@ void help_func(int argc, char *argv[]) show_help(); } -static void parse_cpuid(const char *arg, int *cpuid) +static int parse_cpuid_non_fatal(const char *arg, int *cpuid) { if ( sscanf(arg, "%d", cpuid) != 1 || *cpuid < 0 ) { if ( strcasecmp(arg, "all") ) - { - fprintf(stderr, "Invalid CPU identifier: '%s'\n", arg); - exit(EINVAL); - } + return -1; + *cpuid = -1; } + + return 0; +} + +static void parse_cpuid(const char *arg, int *cpuid) +{ + if ( parse_cpuid_non_fatal(arg, cpuid) ) + { + fprintf(stderr, "Invalid CPU identifier: '%s'\n", arg); + exit(EINVAL); + } } static void parse_cpuid_and_int(int argc, char *argv[],