From patchwork Wed Apr 24 23:15:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thiago Jung Bauermann X-Patchwork-Id: 88974 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 762B9384640E for ; Wed, 24 Apr 2024 23:16:53 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by sourceware.org (Postfix) with ESMTPS id 388D43846410 for ; Wed, 24 Apr 2024 23:15:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 388D43846410 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 388D43846410 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714000561; cv=none; b=Wg7zGwfTH8g67XGBBHjZ32XOLrm5tOMdZLAbcPU9mFXEt/cZ/53H20+1u2GhgaaBHd4mYfU6rAwBgSS16V4n1rySeTLpNmqBg3c5aYaZr040FgrS88hKZyigPJgAcyDtunVwf7+CG4dAzRfDr3qSewztBavbnpcP5er4UQvzYi0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714000561; c=relaxed/simple; bh=1xGhkGDmn9yKghDG/UQUQESMBKjS89m7wdcPxf2ymNU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=GKTx8WyEL8BnY7yPX+qGHNpZ9GyZ/qQif6PzBaSfhzIp4/HZVGZTJyJq+ZbcqOatFA1elrxRdBEe8PB0p+ltnO/ap+SGmYUz8NWfVgoOusx+D1/+KNBHwd+b+AkegXjZmDCBEx3ItFV8U4AcI0u54qLIAoq4itPawl/l66mLQ4o= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1e83a2a4f2cso2662075ad.1 for ; Wed, 24 Apr 2024 16:15:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1714000558; x=1714605358; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fYBh+n9IwUhNo/7khRr/3J4ptTWU7xn/Zet84InQcgE=; b=oWKvCDbPCBVy2CtMX3UDKmg5ePZckvhOi3uEXXkLs9I0VsH51DFstv+PY9FReUrjuG LFiHtu19bGWPZz6OTrUVxqscmAf/Fn3SxHapmXKnSSEVtuVH/jAmxOLBM41wl0xjazXJ nuqfs7tP6Wxs7fGjAZ12c5nhbJg8/AykThsvVNOzAZYwnetfWUrJMI+ctw+cXoJke/rp ZC05Hl7HEOt1TKu3zf5GM+C6QP0TXphSQbVzFHBC/12gZ5LnIfZRCaPTzG29R0+Gl10J 4dir2Q5vmfqoY6wEMttqQ1umCw08HKVGzt2AXvEx8Km8ojRukuJsqZY4NwPpvyAefoRl BWHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714000558; x=1714605358; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fYBh+n9IwUhNo/7khRr/3J4ptTWU7xn/Zet84InQcgE=; b=eEmsHRozE77mMZDV/zWFdXD3OESByOtkqCU1fPoHnzOROd5goAnqroVcIlWUEvXMiz gNwdLWUFBa0Zc/AVRAgKr6hYbSzbefsON+iAIE6hbOluShrhDsg7yLNQfX2zSB5PJuWf RF5dGeNCEEcvovXejzcOZmjF3UqOjd1MBGavhK5ptPEKBz1xA32btmJHn74ZzIsQy+Jd jd5zEXxOHZwDc7FtLG/UICIKLHUKYN5W/f2S3UvjqiJg5VIU97liJ8qtaDGLq65Rawcu WgTU8ZuYlSBKjh8F7txiNlbWXgt5iCnPNNwJw5+vm52PUhZ3P8+Pr+bKUEgdSCQ0Nw0S bc1w== X-Gm-Message-State: AOJu0YxvoZ+ecaxQWtTqW+ncIZTazqK4z3tB3ISPBZzGi09jzgUqejPC cWDg8s7CJwAIIZjqQIdHvTMCNuM0nuO6cO4arWWHHaF/cGyAQ7MjamBm14Wh/RVCQsK4QuF1kSg k X-Google-Smtp-Source: AGHT+IGJ1t4R+tD9FnNyVy9WBNTab+kii4OO6Fs4t4NxqKEH6245pYJCorjUkDnZ/QC1gvXiHzFATw== X-Received: by 2002:a17:902:7488:b0:1e2:a91c:9836 with SMTP id h8-20020a170902748800b001e2a91c9836mr3893078pll.33.1714000558122; Wed, 24 Apr 2024 16:15:58 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8470:b65d:315b:9fcb:d747]) by smtp.gmail.com with ESMTPSA id ba5-20020a170902720500b001e2b4f513e1sm12433555plb.106.2024.04.24.16.15.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 16:15:57 -0700 (PDT) From: Thiago Jung Bauermann To: gdb-patches@sourceware.org Cc: Christophe Lyon , Luis Machado , Pedro Alves Subject: [PATCH v3 1/3] gdb/nat: Use procfs(5) indexes in linux_common_core_of_thread Date: Wed, 24 Apr 2024 20:15:49 -0300 Message-ID: <20240424231551.1577518-2-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240424231551.1577518-1-thiago.bauermann@linaro.org> References: <20240424231551.1577518-1-thiago.bauermann@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org The code and comment reference stat fields by made-up indexes. The procfs(5) man page, which describes the /proc/PID/stat file, has a numbered list of these fields so it's more convenient to use those numbers instead. This is currently an implementation detail inside the function so it's not really relevant with the code as-is, but a future patch will do some refactoring which will make the index more prominent. Therefore, make this change in a separate patch so that it's simpler to review. Reviewed-By: Luis Machado --- gdb/nat/linux-osdata.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) Changes in v3: - Use macro names in comment, and clarify why we use those fields (suggested by Pedro). Changes in v2: - Added macros for field indexes in /proc/PID/stat (Suggested by Luis). diff --git a/gdb/nat/linux-osdata.c b/gdb/nat/linux-osdata.c index 6ffabe90aa7d..4812bc735e86 100644 --- a/gdb/nat/linux-osdata.c +++ b/gdb/nat/linux-osdata.c @@ -52,6 +52,10 @@ typedef long long TIME_T; #define MAX_PID_T_STRLEN (sizeof ("-9223372036854775808") - 1) +/* Index of fields of interest in /proc/PID/stat, from procfs(5) man page. */ +#define LINUX_PROC_STAT_STATE 3 +#define LINUX_PROC_STAT_PROCESSOR 39 + /* Returns the CPU core that thread PTID is currently running on. */ /* Compute and return the processor core of a given thread. */ @@ -74,10 +78,9 @@ linux_common_core_of_thread (ptid_t ptid) if (pos == std::string::npos) return -1; - /* If the first field after program name has index 0, then core number is - the field with index 36 (so, the 37th). There's no constant for that - anywhere. */ - for (int i = 0; i < 37; ++i) + /* The first field after program name is LINUX_PROC_STAT_STATE, and we are + interested in field LINUX_PROC_STAT_PROCESSOR. */ + for (int i = LINUX_PROC_STAT_STATE; i <= LINUX_PROC_STAT_PROCESSOR; ++i) { /* Find separator. */ pos = content->find_first_of (' ', pos);