Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp1600953lqg; Sun, 3 Mar 2024 19:08:18 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWO2dQZCfAArxVM7u7GNaduG0dIBrANyIiifpQc4fV378iIbsZcLfIMOXL9ZwUvBeGhZSkLvDX03xw7duO+CQJ06zVujMC/eHnt5CL2Zw== X-Google-Smtp-Source: AGHT+IGYd/8+S6+pKKWmkNGhhxC9xRq2C8gZ81FD3CkjZ0w1AJ9YGAFGzV6teg3k2Is3qd549GWR X-Received: by 2002:a05:6358:c97:b0:17b:f6d6:2d54 with SMTP id o23-20020a0563580c9700b0017bf6d62d54mr10334365rwj.28.1709521698483; Sun, 03 Mar 2024 19:08:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709521698; cv=pass; d=google.com; s=arc-20160816; b=D3bDtCuIBCKia+oW1iQ51vyePnVi0kj56yg+K9ieBGQLIOgrVXXMjWB2gJCEoWzdFd ExoP4HPwy6DB27YEob1kXs7eGHXgrtDbozG6mBM+Hr738O8o4a8nxlvkxST9L/ge/uIc g37Gpc/65OFccZ3teajCMR94sX11ERfb46cZn5PxG1Cw0xIFLueY9mQN4FOlBIxfqRYp R5CmHiRvRWnoVgzqAmvj+TrYt+WzWl0/NfjuXbRpcPJP0SiMjbtxb31frs6WnZ02AUeJ 2ijxOLmejK6X4RHxgAhDFRZNw9zXinwRuBDkcUmGsrvehyWDpBNVU2DftgknD5FqolfC u/+w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id:dkim-signature; bh=aUDui+SoGtCzCcd28AP+HAZizOhj0wayhw6lwCsOegY=; fh=FbJ/LNaWObDAkaiPu5oOcgA5bmiqEUfSKAzTBEWC3fo=; b=NNYJoJokEzJuIQxBol2tLBpGJURBIgrENpi3051UvncdvLR1DAPbLqIrX8qEGs8VC6 ZLUVHXl/r680XHwJVv5n8r/9KQGcxzfqEGbkG07AOXXfhLDNI3nLCMOlCkhzGg4o63W9 ETeNsK2nnL6mUC5uMU45lNa1mnAxbCv90y12OetMRlrcs2MDzMtchw4Wj3YDne0XVkF5 Ltl3RW96sdemH3C6FfW6QANq/nHlR+scNn8dDF4cGsBXSnx2/Xd8y6zZmIAio1HlfQYc lA2sigYpTjx7BAB8Mfwk7Hw0X71ACtXc0BgeHln9ZzffifQRVxvnMTK9+lWsk9BwKyT0 ScSQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@shopee.com header.s=shopee.com header.b=W3gYmJ5K; arc=pass (i=1 spf=pass spfdomain=shopee.com dkim=pass dkdomain=shopee.com dmarc=pass fromdomain=shopee.com); spf=pass (google.com: domain of linux-kernel+bounces-89999-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89999-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=shopee.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id gh3-20020a05621429c300b006903078e18dsi8755138qvb.221.2024.03.03.19.08.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 19:08:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-89999-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@shopee.com header.s=shopee.com header.b=W3gYmJ5K; arc=pass (i=1 spf=pass spfdomain=shopee.com dkim=pass dkdomain=shopee.com dmarc=pass fromdomain=shopee.com); spf=pass (google.com: domain of linux-kernel+bounces-89999-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89999-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=shopee.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 2C69D1C20F8C for ; Mon, 4 Mar 2024 03:08:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B5D77522D; Mon, 4 Mar 2024 03:08:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=shopee.com header.i=@shopee.com header.b="W3gYmJ5K" Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EDB5917C9 for ; Mon, 4 Mar 2024 03:08:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709521684; cv=none; b=kklfAn24y1K44zP69zjXkNbt5PxAQJP2HzYzWZSRLtW3CmOF801KkcNt7Q7y9ZcJ9R6QDKbBxFUxCGV6jH8ozDaucH/oN/MOPYwoGhEIr6ovF1N63qtfDnCTk3hc5XH8dfqld68f9xZvYQ/JCwgnj0/76lio+23KSfP/dp8lGrI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709521684; c=relaxed/simple; bh=yZYo83Z2W6CRyr8MaaAUL6vnyuB7o2l8XMnQn64c75s=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=S3kgyL/RgJZLZ49PytFwQw40Ylb1XfUjJh7mJEKP5AWZN9M63fvzsctakTn8nHpKQabUz4qOCma04eWDlswYVvdnB4XT9l4gQ1H4Kw9V7914rGfSEUxm4eelQWNtTn0mFkwY/XOAOTtZx+tfb79QupTAH2VMLZjmuIuW10h8ESc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=shopee.com; spf=pass smtp.mailfrom=shopee.com; dkim=pass (2048-bit key) header.d=shopee.com header.i=@shopee.com header.b=W3gYmJ5K; arc=none smtp.client-ip=209.85.214.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=shopee.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=shopee.com Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1dca160163dso39040225ad.3 for ; Sun, 03 Mar 2024 19:08:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shopee.com; s=shopee.com; t=1709521682; x=1710126482; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=aUDui+SoGtCzCcd28AP+HAZizOhj0wayhw6lwCsOegY=; b=W3gYmJ5K5WHJM7Iylv36P60GH/1Q+gu/LoXWLpDAiJ2vz/S+G4e4A4uwoXsvUXjefG pkM4veUAg+sPpFKmyZVMe9/ikXNsMSaiXT4sq6KJWF+E3hS85LQzu67DCnRzdM8JwpDp TXAu/j4zNOMdo2U3INHc2k4aJlln4ZNDskYBo6zRBLcm/k7u6JtZzfcG4A4vJ/NHcO47 rT2+mQOgr/LqKkerNJTFso0d/r2YA3+jkOEaFK2SWrVl3APdSD3Fu5bvkKl1LNeAmeHy YysgqZdFxpbb24P8VHTYnqwf0PurqYnmHpF+GtvWNZJ5DLf/AsXBp2RCScIgvbN9MyIA 2VTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709521682; x=1710126482; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=aUDui+SoGtCzCcd28AP+HAZizOhj0wayhw6lwCsOegY=; b=wfJuqwzv5c3Sihmlrz62+hGz4eWyfnsFuqPFS8cSEXuyV2jE+NKoPuRZZgclMBJyaM n541FhEu7NJPfgX3jRlzdvSzGXqAeKuuW13s7fOmcU8XGQbLiNLKnPwiWCO1zhoIahXH mpVzIi66QnwfTzYtJL8/ii9TsFx4YSsUXTaq1lW3d5geFjKPAnWtzsl2ghDdz1HYD4pq DlC0C3oMxhIB8+ERew+TegYgaZUiU2zVmunHyGZkQwwnl7WA1CGFT7R8KUXb1Ht0xxoV vHedSZq8chrucBZx6QRXADju50NhyqYzrJar2mcbFVk6+epC0Tmp1JOdFxwnkLquFLi1 iSxg== X-Forwarded-Encrypted: i=1; AJvYcCWuBhiI2v7CtvZAoxY/e7iR/bcFVdpPcyMzgF6Xk29fF8wojkgP/HgJOOemT03iVt1a39dxpFu4nFw5oIv3aPVlp/OLSHZ+poLPTgbR X-Gm-Message-State: AOJu0YzUcrQwCpudn5Ybqjsh4+5t2PcIYPFJwy65rKMXAyGLSPU7KLKw 5wfRzqtvoVagn0zgTMPstIBGnos5SQtXCWSbZPFzUu77UKuY7adqzFTn6wkPnKWMoQV4eVo/qbh 4UnJy2g== X-Received: by 2002:a17:902:d3c4:b0:1db:ccd0:e77e with SMTP id w4-20020a170902d3c400b001dbccd0e77emr8078485plb.35.1709521682152; Sun, 03 Mar 2024 19:08:02 -0800 (PST) Received: from [10.54.24.74] (static-ip-148-99-134-202.rev.dyxnet.com. [202.134.99.148]) by smtp.gmail.com with ESMTPSA id c7-20020a170902d48700b001db5079b705sm7289466plg.36.2024.03.03.19.07.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 03 Mar 2024 19:08:01 -0800 (PST) Message-ID: <668d1f61-9111-4239-9766-f43bef3a9828@shopee.com> Date: Mon, 4 Mar 2024 11:07:57 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/2] x86/resctrl: Add tracepoint for llc_occupancy tracking To: James Morse , reinette.chatre@intel.com Cc: fenghua.yu@intel.com, babu.moger@amd.com, peternewman@google.com, x86@kernel.org, linux-kernel@vger.kernel.org References: <20240229071125.100991-1-haifeng.xu@shopee.com> <20240229071125.100991-3-haifeng.xu@shopee.com> <4ddba36d-3c7d-4412-8b09-d55af493423e@arm.com> From: Haifeng Xu In-Reply-To: <4ddba36d-3c7d-4412-8b09-d55af493423e@arm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 2024/3/2 01:47, James Morse wrote: > Hello! > > On 29/02/2024 07:11, Haifeng Xu wrote: >> In our production environment, after removing monitor groups, those unused >> RMIDs get stuck in the limbo list forever because their llc_occupancy are >> always larger than the threshold. But the unused RMIDs can be successfully >> freed by turning up the threshold. >> >> In order to know how much the threshold should be, perf can be used to acquire >> the llc_occupancy of RMIDs in each rdt domain. >> >> Instead of using perf tool to track llc_occupancy and filter the log manually, >> it is more convenient for users to use tracepoint to do this work. So add a new >> tracepoint that shows the llc_occupancy of busy RMIDs when scanning the limbo >> list. > >> diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c >> index c34a35ec0f03..ada392ca75b2 100644 >> --- a/arch/x86/kernel/cpu/resctrl/monitor.c >> +++ b/arch/x86/kernel/cpu/resctrl/monitor.c >> @@ -362,6 +363,13 @@ void __check_limbo(struct rdt_domain *d, bool force_free) > > [expanded the diff hunk for better context] >> entry = __rmid_entry(idx); >> if (resctrl_arch_rmid_read(r, d, entry->closid, entry->rmid, >> QOS_L3_OCCUP_EVENT_ID, &val, >> arch_mon_ctx)) { >> rmid_dirty = true; >> } else { >> rmid_dirty = (val >= resctrl_rmid_realloc_threshold); >> } >> >> if (force_free || !rmid_dirty) { >> clear_bit(idx, d->rmid_busy_llc); >> if (!--entry->busy) >> limbo_release_entry(entry); >> } > >> cur_idx = idx + 1; > > Ideally this would be the last line in the loop, its how the iterator advances to the next > bit in the bitmap. > > >> + /* x86's CLOSID and RMID are independent numbers, so the entry's >> + * closid is a invalid CLOSID. But on arm64, the RMID value isn't >> + * a unique number for each CLOSID. It's necessary to track both >> + * CLOSID and RMID because there may be dependencies between each >> + * other on some architectures */ >> + trace_mon_llc_occupancy_limbo(entry->closid, entry->rmid, d->id, val); > > I agree outputting both these values is the right thing to do. > > resctrl_arch_rmid_read() could return an error, in which case val here is either > uninitialised, or the value of another RMID. > Could you put the tracepoint in the 'else' section of the if/else after > resctrl_arch_rmid_read()? This way it will only output a value to user-space if it is correct. > > >> diff --git a/arch/x86/kernel/cpu/resctrl/trace.h b/arch/x86/kernel/cpu/resctrl/trace.h >> index 495fb90c8572..35149a75c951 100644 >> --- a/arch/x86/kernel/cpu/resctrl/trace.h >> +++ b/arch/x86/kernel/cpu/resctrl/trace.h >> @@ -35,6 +35,21 @@ TRACE_EVENT(pseudo_lock_l3, >> TP_printk("hits=%llu miss=%llu", >> __entry->l3_hits, __entry->l3_miss)); >> >> +TRACE_EVENT(mon_llc_occupancy_limbo, >> + TP_PROTO(u32 ctrl_hw_id, u32 mon_hw_id, int id, u64 occupancy), >> + TP_ARGS(ctrl_hw_id, mon_hw_id, id, occupancy), >> + TP_STRUCT__entry(__field(u32, ctrl_hw_id) >> + __field(u32, mon_hw_id) > >> + __field(int, id) > > Nit: Could we call this 'domain_id'? We've got two other ids already, so we should be > clear what each one is! > > >> + __field(u64, occupancy)), > > Nit: 'occupancy_bytes'? Just to avoid user-space thinking it needs to convert from the > hardware unit in Intel's SDM ... and just in case we ever have to add another parameter > that is sort of occupancy too. > > >> + TP_fast_assign(__entry->ctrl_hw_id = ctrl_hw_id; >> + __entry->mon_hw_id = mon_hw_id; >> + __entry->id = id; >> + __entry->occupancy = occupancy;), >> + TP_printk("ctrl_hw_id=%u mon_hw_id=%u domain=%d llc_occupancy=%llu", >> + __entry->ctrl_hw_id, __entry->mon_hw_id, __entry->id, __entry->occupancy) >> + ); >> + > > Tracepoints always expose some implicit details of the kernel internals which can make > supporting them a headache. In this case - I've had some discussion with folk about future > work to defer the limbo work as late as possible - until a new control or monitor group is > allocated. This would be to avoid interrupting user-space tasks to update the limbo list > when the result isn't needed until alloc time. > > In this case the tracepoint wouldn't be hit unless user-space made a mkdir() syscall to > force an update - I think this can just be a documentation problem. > > I also don't think we should commit to this outputting values for all dirty RMID - which > it does today. If group creation were to fail because there weren't any free RMID you'd > get all the values, I think this is the only case where user-space would care. Yes. > > Could we document the properties of the the trace-point that can be relied on in > Documentation/arch/x86/resctrl.rst ? > > Something like: > | This tracepoint gives you the precise occupancy values for a subset of RMID that are not > | immediately available for allocation. This can't be relied on to produce output every > | second, it may be necessary to attempt to create an empty monitor group to force an > | update. Output may only be produced if creation of a control or monitor group fails. > > I think we'll always walk a list of dirty RMID before failing to allocate an RMID, so this > should be future proof. > > > With the val and documentation bits: > Reviewed-by: James Morse > > > Thanks, > > James Thanks for your suggestions.