From owner-freebsd-hackers@freebsd.org Tue Mar 19 21:10:47 2019 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id DD0A7153A267 for ; Tue, 19 Mar 2019 21:10:46 +0000 (UTC) (envelope-from m.kaniewski@fudosecurity.com) Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 6D4E16F8B1 for ; Tue, 19 Mar 2019 21:10:45 +0000 (UTC) (envelope-from m.kaniewski@fudosecurity.com) Received: by mail-lf1-x135.google.com with SMTP id u68so232123lff.7 for ; Tue, 19 Mar 2019 14:10:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fudosecurity.com; s=gmail; h=mime-version:from:date:message-id:subject:to :content-transfer-encoding; bh=aKyEAI9etSZrs4bNAutZYIWXUDxEjnVoVDOMktA25Dk=; b=frR+3ImSSdWVsJpoX5j/fnTkHexVt6LJpV6hqzl1CT7v80KrDkyz6ZOER2txDeOgPF GEJio9e5eqOOUGPK1Vstz4KYo5CRMIcn3nOStsx/HQhdX48M0hQSlUcrX/ZRCt6rdMEy /O7A65lpqpuQpTookkN2L/wsZxpDQ7bYLci1o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to :content-transfer-encoding; bh=aKyEAI9etSZrs4bNAutZYIWXUDxEjnVoVDOMktA25Dk=; b=Mc+SPNBpheO63s4NTTRtzlAxpjHlPpQLz62kdc4C3kF2z0TcIiK/FTghPvQO4kDxyz 5y/0IvteXPEkC7nTHpApC9xfZWw3MvlKjkrMftlDJHJiqGeKarEEkNzYcHuB57+C7lpI x90FqHFsHmgDT+2PDkZ49q6IMFHzFWO69riKRZ6HEsOaUSzQoLAF5XTY0ucr00BnM79D T01NybzobEZ0Yzkxb7GhEFm2vg66aUQdhaKCibgdyyI5PFdU5oyO+24aL1ulYLlHDf5B OdFLLTnkanV5gCS8AMX+1BI3AvYhKjPqlIc0sAC2/Uj/qCrOEt4+lFDB2GR8/4xgp83u ZMhg== X-Gm-Message-State: APjAAAW4LkN/MnFEkecWoiDW0uCiapfLBS8qlowaEstmzrn8OEGY1H4r imVyzZIand6OmYRMmVJ7BfxqrSLmwa4w/HuTVQQSKZz+E3s= X-Google-Smtp-Source: APXvYqx4Q29SqggUwe+AgyuOto1MsxRsd3mbxOMdAuvv0AObpHn6xT472eiZ1Z2DsPn/AL9y9lkF6iOZkZzPfciv6dg= X-Received: by 2002:ac2:515b:: with SMTP id q27mr13968760lfd.110.1553029843671; Tue, 19 Mar 2019 14:10:43 -0700 (PDT) MIME-Version: 1.0 From: =?UTF-8?Q?Mi=C5=82osz_Kaniewski?= Date: Tue, 19 Mar 2019 22:10:21 +0100 Message-ID: Subject: sched_pickcpu() and a pinned thread. To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 6D4E16F8B1 X-Spamd-Bar: ------ Authentication-Results: mx1.freebsd.org; dkim=pass header.d=fudosecurity.com header.s=gmail header.b=frR+3ImS; spf=pass (mx1.freebsd.org: domain of m.kaniewski@fudosecurity.com designates 2a00:1450:4864:20::135 as permitted sender) smtp.mailfrom=m.kaniewski@fudosecurity.com X-Spamd-Result: default: False [-6.05 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; R_DKIM_ALLOW(-0.20)[fudosecurity.com:s=gmail]; FROM_HAS_DN(0.00)[]; R_SPF_ALLOW(-0.20)[+ip6:2a00:1450:4000::/36]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-hackers@freebsd.org]; TO_DN_NONE(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; DMARC_NA(0.00)[fudosecurity.com]; DKIM_TRACE(0.00)[fudosecurity.com:+]; MX_GOOD(-0.01)[alt1.aspmx.l.google.com,aspmx.l.google.com,alt3.aspmx.l.google.com,alt2.aspmx.l.google.com,alt4.aspmx.l.google.com]; RCVD_IN_DNSWL_NONE(0.00)[5.3.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.4.6.8.4.0.5.4.1.0.0.a.2.list.dnswl.org : 127.0.5.0]; NEURAL_HAM_SHORT(-0.72)[-0.717,0]; IP_SCORE(-2.83)[ip: (-9.59), ipnet: 2a00:1450::/32(-2.37), asn: 15169(-2.11), country: US(-0.07)]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:15169, ipnet:2a00:1450::/32, country:US]; RCVD_COUNT_TWO(0.00)[2] X-Mailman-Approved-At: Tue, 19 Mar 2019 23:19:17 +0000 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Mar 2019 21:10:47 -0000 Hi, I have an application which exchanges packets between two NIC ports. Most of a CPU time is therefore consumed by the userspace process and two IRQ threads. All of them are pinned to the same CPU using cpu_setaffinity() function so I expect that the scheduler usage should be minimal even on a high network load when a lot of interrupts are generated. I recently find out that my application spends a lot of time in cpu_search_lowest() function. A backtrace shown me that cpu_search_lowest() is called by sched_pickcpu(). I tried to analyze this second function but I don't know what exactly should I expect from it if my thread is pinned to a specific CPU. I assume that the function should get to a point where ts->ts_cpu is returned. However it doesn't do it and sched_pickcpu() always ends looking for the lowest busy CPU using cpu_search_lowest(). In result it finds the CPU that the thread is pinned to but it is very time consuming process. Therefore I suspect that sched_pickcpu() should return before that happens. For interrupt threads I see that there is a special case at the beginning of sched_pickcpu(): /* * Prefer to run interrupt threads on the processors that generate * the interrupt. */ pri =3D td->td_priority; if (td->td_priority <=3D PRI_MAX_ITHD && THREAD_CAN_SCHED(td, self) && curthread->td_intr_nesting_level && ts->ts_cpu !=3D self) { SCHED_STAT_INC(pickcpu_intrbind); ts->ts_cpu =3D self; if (TDQ_CPU(self)->tdq_lowpri > pri) { SCHED_STAT_INC(pickcpu_affinity); return (ts->ts_cpu); } } However IRQ threads from the NIC doesn't fall into this case because ts->ts_cpu =3D=3D self (these variables are equal to the CPU to which my threads are pinned). Is this check required? For non-interrupt threads there are some other possible options where ts->ts_cpu is returned however I am not sure which should handle a pinned thread. I would be grateful if someone would give me some clue how should I understand the sched_pickcpu() function and when it should return in case of a pinned thread. Thanks Mi=C5=82osz Kaniewski