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=-18.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 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 6A5BCC4338F for ; Tue, 24 Aug 2021 15:46:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4D64A60041 for ; Tue, 24 Aug 2021 15:46:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238505AbhHXPrG (ORCPT ); Tue, 24 Aug 2021 11:47:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:54748 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238469AbhHXPrD (ORCPT ); Tue, 24 Aug 2021 11:47:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629819979; 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; bh=sRTtj7soYKz+ErBezLHxKBD2FHdlpZpwJnJfiry7FNI=; b=VcumqYKDDHmwJk08I9sFNDfgnQvgGQKUR2bXyiDGCrRQTLf4lq0j/9UxKdf8ORhDnBZy61 frj1OjtsVAacnULtSjQQeMZFWqCEy4Q/E2kL/SIors+8j5aQKzxC06fkhT2sRIsrHOFj57 mrDSp/1e4zDO9g83MJF51fBY7hJFCIc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-362-OPeFlpI9NTOKMuLbT81NCw-1; Tue, 24 Aug 2021 11:43:24 -0400 X-MC-Unique: OPeFlpI9NTOKMuLbT81NCw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 822D787D550; Tue, 24 Aug 2021 15:43:09 +0000 (UTC) Received: from fuller.cnet (ovpn-112-5.gru2.redhat.com [10.97.112.5]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7BCB460C05; Tue, 24 Aug 2021 15:43:03 +0000 (UTC) Received: by fuller.cnet (Postfix, from userid 1000) id 3261E416D8BC; Tue, 24 Aug 2021 12:42:55 -0300 (-03) Date: Tue, 24 Aug 2021 12:42:55 -0300 From: Marcelo Tosatti To: linux-kernel@vger.kernel.org Cc: Nitesh Narayan Lal , Nicolas Saenz Julienne , Juri Lelli , Peter Zijlstra , Christoph Lameter , Thomas Gleixner Subject: util-linux: add chisol tool to configure task isolation Message-ID: <20210824154255.GA105413@fuller.cnet> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add chisol tool to configure task isolation. See chisol -h for details. For example, to launch a version of oslat that activates task isolation: chisol -q vmstat_sync -I conf ./oslat -f 1 -c 5 -D 5m -q vmstat_sync: enable quiescing of per-CPU vmstats -I conf: inherit task isolation configuration. Signed-off-by: Marcelo Tosatti Index: util-linux/schedutils/chisol.c =================================================================== --- /dev/null +++ util-linux/schedutils/chisol.c @@ -0,0 +1,294 @@ +/* + * chisol.c - change task isolation parameters + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License, version 2, as + * published by the Free Software Foundation + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright (C) 2021 Marcelo Tosatti + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "nls.h" +#include "strutils.h" +#include "xalloc.h" +#include "procutils.h" +#include "c.h" +#include "closestream.h" + +static void __attribute__((__noreturn__)) usage(void) +{ + FILE *out = stdout; + fprintf(out, + _("Usage: %s [options] cmd [args...]]\n\n"), + program_invocation_short_name); + + fputs(USAGE_SEPARATOR, out); + fputs(_("Change task isolation parameters.\n"), out); + fputs(USAGE_SEPARATOR, out); + + fprintf(out, _( + "Options:\n" + " -q, --quiesce configure quiescing of particular activities\n" + " (to list supported activities see --info)\n" + " -i, --info show supported task isolation features\n" + " -a, --activate activate isolation before exec\n" + " -I, --inherit set inheritance across fork/exec.\n" + " Two modes are available: conf, where only task\n" + " isolation configuration is inherited, or active,\n" + " where configuration and activation are inherited.\n" + )); + printf(USAGE_HELP_OPTIONS(20)); + + fputs(USAGE_SEPARATOR, out); + fprintf(out, _( + "Configure task isolation and run a new command:\n" + " %1$s -q vmstat_sync cmd\n" + "Configure, activate task isolation and run a new command:\n" + " %1$s -a -q vmstat_sync cmd\n" + "To query the supported task isolation features:\n" + " %1$s -i\n"), + program_invocation_short_name); + + printf(USAGE_MAN_TAIL("chisol(1)")); + exit(EXIT_SUCCESS); +} + +struct isol_feat_name { + int val; + char *name; +}; + +struct isol_feat_name featnames[] = { + { ISOL_F_QUIESCE, "quiesce" }, +}; + +struct isol_feat_name qfeatnames[] = { + { ISOL_F_QUIESCE_VMSTATS, "vmstat_sync" }, +}; + +#define SSZ sizeof(struct isol_feat_name) + +static char *featname(int val, struct isol_feat_name *fnames, + unsigned int nrentries) +{ + unsigned int i; + char *name; + + for (i = 0; i < nrentries; i++) { + struct isol_feat_name *f = &fnames[i]; + + if (f->val == val) + return strdup(f->name); + } + + name = malloc(100); + snprintf(name, 100, "0x%x\n", val); + + return name; +} + +static void __attribute__((__noreturn__)) task_isol_info(void) +{ + int ret, feats; + unsigned int i, j; + + FILE *out = stdout; + + /* Retrieve supported task isolation features */ + ret = prctl(PR_ISOL_FEAT, 0, 0, 0, 0); + if (ret == -1) { + perror(_("prctl PR_ISOL_FEAT")); + exit(EXIT_FAILURE); + } + feats = ret; + + for (i = 0; i < 16; i++) { + if (feats & (1<