From owner-freebsd-hackers@FreeBSD.ORG Fri Nov 26 03:48:38 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 145EA1065672; Fri, 26 Nov 2010 03:48:38 +0000 (UTC) (envelope-from max@laiers.net) Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.171]) by mx1.freebsd.org (Postfix) with ESMTP id A00F48FC0A; Fri, 26 Nov 2010 03:48:37 +0000 (UTC) Received: from [192.168.0.5] (c-71-197-236-68.hsd1.wa.comcast.net [71.197.236.68]) by mrelayeu.kundenserver.de (node=mreu0) with ESMTP (Nemesis) id 0MflE8-1P7cAv2UGC-00NCBN; Fri, 26 Nov 2010 04:36:02 +0100 Message-ID: <4CEF2B20.4060102@laiers.net> Date: Thu, 25 Nov 2010 19:36:00 -0800 From: Max Laier User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.12) Gecko/20101027 Thunderbird/3.1.6 MIME-Version: 1.0 To: Andriy Gapon References: <4CEB5C4C.90003@freebsd.org> In-Reply-To: <4CEB5C4C.90003@freebsd.org> Content-Type: text/plain; charset=x-viet-vps; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:NvPI2JoXksy8I3DEXZkHDyBOG2api+ASlT6sTv2UR8+ ugsYPgXTe3ocXbhAYUolq4oWahvLxGHzFfW4iTwK+amLNERiES UA9RI3qDVbQ2t7eSE9wibfAJTYMp8cYrdZH7WzkewlG8tLfEbY gUR2RALPf9QlskclqA1BB+V6EPcwGL+yCU+SEtM+d0i8Hl2D6v PsFX692JudrSpR+2uTpgw== X-Mailman-Approved-At: Fri, 26 Nov 2010 04:25:22 +0000 Cc: freebsd-hackers@freebsd.org Subject: Re: smp_rendezvous_cpus() vs sched_bind() X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Nov 2010 03:48:38 -0000 Am 22.11.2010 22:16, schrieb Andriy Gapon: > If I need to call a function func on a specific CPU which one of the following I > should use? > > 1. > smp_rendezvous_cpus(1<< cpuid, ..., func, ...); > > 2. > sched_bind(cpuid); > func(); > sched_unbind(); > > Or does it depend on some additional factors? > What are the main differences here? > > And also by extension. > If I need to execute func() on all CPUs - which one is better again - > smp_rendezvous_cpus() or CPU_FOREACH+sched_bind? > It depends on what you are trying to do in func() really. One huge caveat against smp_rendezvous is that func will be running from interrupt context in an unknown lock state with interrupts disabled. Most of the time sched_bind() should be sufficient/preferrable. You should think of smp_rendezvous as a basic building block rather than a general purpose API ... unless you really need the rendezvous part and the preemption and all that other stuff ... stay clear of it. It might make sense to have one of the deferred action APIs (callout/taskqueue/...) provide means to run a task on a specific CPU/all of them ... I hope this helps. Best, Max