Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3379945rdh; Mon, 27 Nov 2023 12:41:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IHsKJt05bNVou+URDp9xr0Nb6Piru1Tagv1/2KMgfyJM60Jv8PBA8EfqpTZDBuLr3G1DHtf X-Received: by 2002:a17:90b:8d6:b0:285:8aa4:2ed8 with SMTP id ds22-20020a17090b08d600b002858aa42ed8mr10863848pjb.15.1701117718233; Mon, 27 Nov 2023 12:41:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701117718; cv=none; d=google.com; s=arc-20160816; b=ofqnt6wStEx1IBOORwXrwBaLWIGVX+HJq9nud6QfdASj9E1cPutXz/mdXm4ogGxIRn zD/v7tHTwt2nDDuQPiSKceGcDytYIj7g0TcQEB7ZO7TvKJi6oLq+4MbtFsLpTnfYoCoW E8PfdPvKI9cM64FHL6EXpwCUJiizeIzzLjBxtpOAXrIwA1bLl8T7SV04p8oka9kdl1pE l/zrgF1MARQ/Dui5fi7omxg+ZqxrQmIuZX1D7VHSJo8Z0lJJjEdKCSD+PJSFZTDsPBck 3kvke5ddmvLNWD+RMsRlIV0KfD+F3ZXQ8Kw24wvUNQxHBnitko5qZkU3Liz6dBoRQW6U XpoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=l4K6Lj4z8jII9KHfI86VtnivPUcuSuyrPVeih1ksGS0=; fh=ZP5rkIgi+sgQyvA0Nb5diyJQn/QILptIgBv8r67XkSs=; b=IXJSlK5PuWeNvohUPpdiwTV/PswEvbzFVEFWBqvFcNoSMuQYLgEpo1trplXerlvWll lD1vFyYTBm66FoDhNDk/0TG+b17K114JtzJGGVHJK53En/sWw2UihL17sIbNCunzHvGd EeFJDwfCB2eP9v51LjrU1SLx7Bw4bvBAHRbKBbZ5O+9rcpax/LUB6p/VhCiLg9aWubrM rYnGpMVa2/blNrm9oZ5IR9IJRnebGqYnxLUuPr15HSKad9fIzxuumvCNuolgeoFxlrGe 5iJLaK6oTH+8vQfDvRdXrNp7m44gzud2HXqCrC2qtSD0W3KMUoivKILLJs9ZA0lZtaHY Gnzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=SX+NmCAq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id lk17-20020a17090b33d100b00285f2c4dc2csi601343pjb.144.2023.11.27.12.41.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 12:41:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=SX+NmCAq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id E49F58182EC3; Mon, 27 Nov 2023 12:41:55 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232596AbjK0Ulk (ORCPT + 99 others); Mon, 27 Nov 2023 15:41:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231601AbjK0Ulj (ORCPT ); Mon, 27 Nov 2023 15:41:39 -0500 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70EE2191 for ; Mon, 27 Nov 2023 12:41:45 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-40b35199f94so262325e9.0 for ; Mon, 27 Nov 2023 12:41:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701117704; x=1701722504; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=l4K6Lj4z8jII9KHfI86VtnivPUcuSuyrPVeih1ksGS0=; b=SX+NmCAqfhLqt6MrlqNhoZj9BkD1J7uX25aX7M9g+L1YFeO1764xAdt0gaKHTFSaqR EyWOBrjebu/lIT/Njk3RaTn7vWp5G45qemiCXXgnYNWHAlrG52Du77Yuklf7TbEDn2uj 4gXGpbq1MXk3/RnV6YtxJ45kGKWYN4o7lgbON9gTZhKoVOvCGDSqnfcUNrNKrBj4S/Wt npPztinlDxKpENfyy5zh0pYj4oNpUghHz1n4yIEE/NwezSFYkpJHuIufsi/CwhSpdhmd Xuic1ZyU7p3MV+Iz0Ds8PukfJzUK9Yt2Xk6XOzQ8O8YR6+PMEb7sHtTCHyDnwuPScP8T sHzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701117704; x=1701722504; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=l4K6Lj4z8jII9KHfI86VtnivPUcuSuyrPVeih1ksGS0=; b=lQqCs3rdHckx/jXPLnOTkbQpWDWjPnhwl8PZc5/bfIGmjTcxE9jCjgmcUbbwmPUSqJ eKiz1Z0Fic9jTSobBONy1laAx+gb77eG7R78UT/HGcIWdfEpu4zNNq4724dDUhbOQxju MosKud7244uFrcYNFM7DUK0EQu9FzQE080IKZg2DlMIE6m4M0HFQn2GTLZ0DHWyC2xqN aAaT2ThS6MeMgdVjSygkDTtzCXmtBf6sDjGWILbwHiK3mmCTiTnxyR2AlsrZBvNOwl14 2TW6jBNQTIfiL8hkjPb4kALEOvnaqpkiKWyLbTklsYIG7LvyO/eTEupzgy6MCRQfCeJb genA== X-Gm-Message-State: AOJu0Yzy9xF2wDBIoEcVQ/YodNe9PwFx19E/5PzyGuUb5TGMfppimh7H ZzK2qlXBrcuxdn+OwekvH4sUIqomTrZty3DIx5bwlA== X-Received: by 2002:a05:600c:206:b0:40b:443d:9b78 with SMTP id 6-20020a05600c020600b0040b443d9b78mr202972wmi.0.1701117703673; Mon, 27 Nov 2023 12:41:43 -0800 (PST) MIME-Version: 1.0 References: <20231102175735.2272696-1-irogers@google.com> <20231102175735.2272696-8-irogers@google.com> In-Reply-To: From: Ian Rogers Date: Mon, 27 Nov 2023 12:41:32 -0800 Message-ID: Subject: Re: [PATCH v4 07/53] tools api fs: Avoid reading whole file for a 1 byte bool To: Namhyung Kim Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Nick Terrell , Kan Liang , Andi Kleen , Kajol Jain , Athira Rajeev , Huacai Chen , Masami Hiramatsu , Vincent Whitchurch , "Steinar H. Gunderson" , Liam Howlett , Miguel Ojeda , Colin Ian King , Dmitrii Dolgov <9erthalion6@gmail.com>, Yang Jihong , Ming Wang , James Clark , K Prateek Nayak , Sean Christopherson , Leo Yan , Ravi Bangoria , German Gomez , Changbin Du , Paolo Bonzini , Li Dong , Sandipan Das , liuwenyu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Mon, 27 Nov 2023 12:41:56 -0800 (PST) On Sun, Nov 5, 2023 at 7:56=E2=80=AFPM Namhyung Kim w= rote: > > On Thu, Nov 2, 2023 at 10:58=E2=80=AFAM Ian Rogers w= rote: > > > > sysfs__read_bool used the first byte from a fully read file into a > > string. It then looked at the first byte's value. Avoid doing this and > > just read the first byte. > > > > Signed-off-by: Ian Rogers > > --- > > tools/lib/api/fs/fs.c | 18 +++++++++--------- > > 1 file changed, 9 insertions(+), 9 deletions(-) > > > > diff --git a/tools/lib/api/fs/fs.c b/tools/lib/api/fs/fs.c > > index 496812b5f1d2..4c35a689d1fc 100644 > > --- a/tools/lib/api/fs/fs.c > > +++ b/tools/lib/api/fs/fs.c > > @@ -447,15 +447,16 @@ int sysfs__read_str(const char *entry, char **buf= , size_t *sizep) > > > > int sysfs__read_bool(const char *entry, bool *value) > > { > > - char *buf; > > - size_t size; > > - int ret; > > + struct io io; > > + char bf[16]; > > + int ret =3D 0; > > > > - ret =3D sysfs__read_str(entry, &buf, &size); > > - if (ret < 0) > > - return ret; > > + io.fd =3D open(entry, O_RDONLY); > > The entry is a name in sysfs, so you need to get the full name. > > Thanks, > Namhyung Thanks, added in v5. Ian > > > + if (io.fd < 0) > > + return -errno; > > > > - switch (buf[0]) { > > + io__init(&io, io.fd, bf, sizeof(bf)); > > + switch (io__get_char(&io)) { > > case '1': > > case 'y': > > case 'Y': > > @@ -469,8 +470,7 @@ int sysfs__read_bool(const char *entry, bool *value= ) > > default: > > ret =3D -1; > > } > > - > > - free(buf); > > + close(io.fd); > > > > return ret; > > } > > -- > > 2.42.0.869.gea05f2083d-goog > >