From owner-freebsd-hackers@FreeBSD.ORG Wed Oct 16 13:29:08 2013 Return-Path: Delivered-To: freebsd-hackers@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 24E0030A; Wed, 16 Oct 2013 13:29:08 +0000 (UTC) (envelope-from alfred@freebsd.org) Received: from elvis.mu.org (elvis.mu.org [192.203.228.196]) by mx1.freebsd.org (Postfix) with ESMTP id 1148C2D4A; Wed, 16 Oct 2013 13:29:07 +0000 (UTC) Received: from Alfreds-MacBook-Pro-9.local (c-76-21-10-192.hsd1.ca.comcast.net [76.21.10.192]) by elvis.mu.org (Postfix) with ESMTPSA id 869371A3C1D; Wed, 16 Oct 2013 06:29:07 -0700 (PDT) Message-ID: <525E94A5.7060809@freebsd.org> Date: Wed, 16 Oct 2013 06:29:09 -0700 From: Alfred Perlstein User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:24.0) Gecko/20100101 Thunderbird/24.0.1 MIME-Version: 1.0 To: Sebastian Huber , Ian Lepore Subject: Re: Global variables in system programs References: <525D5A35.4040005@embedded-brains.de> <525D62D9.4050001@freebsd.org> <1381852662.42859.130.camel@revolution.hippie.lan> <525E4A6F.40904@embedded-brains.de> In-Reply-To: <525E4A6F.40904@embedded-brains.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: FreeBSD Hackers X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 13:29:08 -0000 On 10/16/13 1:12 AM, Sebastian Huber wrote: > On 2013-10-15 17:57, Ian Lepore wrote: >> On Tue, 2013-10-15 at 08:44 -0700, Alfred Perlstein wrote: >>> On 10/15/13 8:07 AM, Sebastian Huber wrote: >>>> Hello, >>>> >>>> I work currently on a port of the FreeBSD network stack to a real-time >>>> operating system for embedded targets. Here the applications are >>>> statically linked with the operating system and the network stack. We >>>> would like to use the standard FreeBSD system programs to configure >>>> the network stack, e.g. ROUTE(8), IFCONFIG(8), etc. For example >>>> >>>> static const char *const argv[] = { >>>> "ifconfig", >>>> "lo0", >>>> "127.0.0.1" >>>> }; >>>> >>>> ifconfig(3, &argv[0]); >>>> >>>> These programs use some global variables. In a statically linked >>>> context we have now the following problems >>>> >>>> o we cannot call the programs concurrently, >>>> >>>> o we have to initialize the values each time. >>>> >>>> We would like to follow the FreeBSD sources to stay up-to-date. So it >>>> is desirable for us to keep the divergence from the original sources >>>> as small as possible. Are patches acceptable for the FreeBSD project >>>> that alter system programs such that >>>> >>>> o global variables are moved into context structures, >>>> >>>> o constant global variables are declared as "const", and >>>> >>>> o variables and functions are declared as "static" if possible? >>>> >>>> Attached is a patch for the ROUTE(8) program to give an example. >>> >>> Wow! I would really love to see this sort of change make it into >>> FreeBSD, not only for linking them all together, but also for running >>> them as threads. > > Out of curiosity, what is the benefit of running these programs in a > thread in case you have an operating system with proper processes? Imagine a program or some shell which loads a bunch of shared objects so instead of needing to fork/exec for each command can just dispatch to a thread. It would let that program be very fast as opposed to a traditional fork/exec model. -Alfred