VirtualBox

Changeset 3173 in kBuild for trunk/src/kmk/kmkbuiltin.c


Ignore:
Timestamp:
Mar 21, 2018 9:37:41 PM (7 years ago)
Author:
bird
Message:

kmkbultin: environment fixes and stats.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/kmkbuiltin.c

    r3172 r3173  
    55
    66/*
    7  * Copyright (c) 2005-2010 knut st. osmundsen <[email protected]>
     7 * Copyright (c) 2005-2018 knut st. osmundsen <[email protected]>
    88 *
    99 * This file is part of kBuild.
     
    2424 */
    2525
    26 /*******************************************************************************
    27 *   Header Files                                                               *
    28 *******************************************************************************/
     26
     27/*********************************************************************************************************************************
     28*   Header Files                                                                                                                 *
     29*********************************************************************************************************************************/
    2930#include <string.h>
    3031#include <stdlib.h>
     
    3940#include "makeint.h"
    4041#include "job.h"
     42#include "variable.h"
    4143#if defined(KBUILD_OS_WINDOWS) && defined(CONFIG_NEW_WIN_CHILDREN)
    4244# include "w32/winchildren.h"
     
    4850extern char **environ;
    4951#endif
     52
     53
     54/*********************************************************************************************************************************
     55*   Global Variables                                                                                                             *
     56*********************************************************************************************************************************/
     57#ifdef CONFIG_WITH_KMK_BUILTIN_STATS
     58extern int print_stats_flag;
     59#endif
     60
    5061
    5162
     
    234245static const KMKBUILTINENTRY g_aBuiltIns[] =
    235246{
    236 #define BUILTIN_ENTRY(a_fn, a_sz, a_uFnSignature, fMpSafe, fNeedEnv) \
     247#define BUILTIN_ENTRY(a_fn, a_sz, a_uFnSignature, fMtSafe, fNeedEnv) \
    237248    {  { { sizeof(a_sz) - 1, a_sz, } }, \
    238        (uintptr_t)a_fn,                                 a_uFnSignature,   fMpSafe, fNeedEnv }
     249       (uintptr_t)a_fn,                                 a_uFnSignature,   fMtSafe, fNeedEnv }
    239250
    240251    /* More frequently used commands: */
     
    245256    BUILTIN_ENTRY(kmk_builtin_kDepObj,  "kDepObj",      FN_SIG_MAIN,            1, 0),
    246257#ifdef KBUILD_OS_WINDOWS
    247     BUILTIN_ENTRY(kmk_builtin_kSubmit,  "kSubmit",      FN_SIG_MAIN_SPAWNS,     0, 0),
     258    BUILTIN_ENTRY(kmk_builtin_kSubmit,  "kSubmit",      FN_SIG_MAIN_SPAWNS,     0, 1),
    248259#endif
    249260    BUILTIN_ENTRY(kmk_builtin_mkdir,    "mkdir",        FN_SIG_MAIN,            0, 0),
    250261    BUILTIN_ENTRY(kmk_builtin_mv,       "mv",           FN_SIG_MAIN,            0, 0),
    251     BUILTIN_ENTRY(kmk_builtin_redirect, "redirect",     FN_SIG_MAIN_SPAWNS,     0, 1),
     262    BUILTIN_ENTRY(kmk_builtin_redirect, "redirect",     FN_SIG_MAIN_SPAWNS,     1, 1),
    252263    BUILTIN_ENTRY(kmk_builtin_rm,       "rm",           FN_SIG_MAIN,            0, 1),
    253264    BUILTIN_ENTRY(kmk_builtin_rmdir,    "rmdir",        FN_SIG_MAIN,            0, 0),
     
    347358                /*
    348359                 * That's a match!
     360                 *
     361                 * First get the environment if it is actually needed.  This is
     362                 * especially important when we run on a worker thread as it must
     363                 * not under any circumstances do stuff like target_environment.
    349364                 */
    350                 int rc;
     365                int    rc;
     366                char **papszEnvVars = NULL;
     367                if (pEntry->fNeedEnv)
     368                {
     369                    papszEnvVars = pChild->environment;
     370                    if (!papszEnvVars)
     371                        pChild->environment = papszEnvVars = target_environment(pChild->file);
     372                }
     373
    351374#if defined(KBUILD_OS_WINDOWS) && defined(CONFIG_NEW_WIN_CHILDREN)
    352                 if (pEntry->fMpSafe)
    353                 {
    354                     rc = MkWinChildCreateBuiltIn(pEntry, argc, argv, pEntry->fNeedEnv ? pChild->environment : NULL,
    355                                                  pChild, pPidSpawned);
     375                /*
     376                 * If the built-in is multi thread safe, we will run it on a job slot thread.
     377                 */
     378                if (pEntry->fMtSafe)
     379                {
     380                    rc = MkWinChildCreateBuiltIn(pEntry, argc, argv, papszEnvVars, pChild, pPidSpawned);
    356381# ifdef CONFIG_WITH_KMK_BUILTIN_STATS
    357382                    g_aBuiltInStats[pEntry - &g_aBuiltIns[0]].cAsyncTimes++;
     
    361386#endif
    362387                {
    363                     char **envp = pChild->environment ? pChild->environment : environ;
    364 
    365388                    /*
    366389                     * Call the worker function, making sure to preserve umask.
    367390                     */
    368391#ifdef CONFIG_WITH_KMK_BUILTIN_STATS
    369                     big_int nsStart = nano_timestamp();
     392                    big_int nsStart = print_stats_flag ? nano_timestamp() : 0;
    370393#endif
    371394                    int const iUmask = umask(0);        /* save umask */
     
    373396
    374397                    if (pEntry->uFnSignature == FN_SIG_MAIN)
    375                         rc = pEntry->u.pfnMain(argc, argv, envp);
     398                        rc = pEntry->u.pfnMain(argc, argv, papszEnvVars);
    376399                    else if (pEntry->uFnSignature == FN_SIG_MAIN_SPAWNS)
    377                         rc = pEntry->u.pfnMainSpawns(argc, argv, envp, pChild, pPidSpawned);
     400                        rc = pEntry->u.pfnMainSpawns(argc, argv, papszEnvVars, pChild, pPidSpawned);
    378401                    else if (pEntry->uFnSignature == FN_SIG_MAIN_TO_SPAWN)
    379402                    {
     
    383406                         * problem then (the call stack shows what's been going on).
    384407                         */
    385                         rc = pEntry->u.pfnMainToSpawn(argc, argv, envp, ppapszArgvToSpawn);
     408                        rc = pEntry->u.pfnMainToSpawn(argc, argv, papszEnvVars, ppapszArgvToSpawn);
    386409                        if (   !rc
    387410                            && *ppapszArgvToSpawn
     
    410433
    411434#ifdef CONFIG_WITH_KMK_BUILTIN_STATS
    412                     g_aBuiltInStats[pEntry - &g_aBuiltIns[0]].cTimes++;
    413                     g_aBuiltInStats[pEntry - &g_aBuiltIns[0]].cNs += nano_timestamp() - nsStart;
     435                    if (print_stats_flag)
     436                    {
     437                        uintptr_t iEntry = pEntry - &g_aBuiltIns[0];
     438                        g_aBuiltInStats[iEntry].cTimes++;
     439                        g_aBuiltInStats[iEntry].cNs += nano_timestamp() - nsStart;
     440                    }
    414441#endif
    415442                }
     
    442469extern void kmk_builtin_print_stats(FILE *pOutput, const char *pszPrefix)
    443470{
    444     const unsigned  cEntries = sizeof(g_aBuiltInStats) / sizeof(g_aBuiltInStats[0]);
     471    const unsigned cEntries = sizeof(g_aBuiltInStats) / sizeof(g_aBuiltInStats[0]);
    445472    unsigned i;
     473    assert(print_stats_flag);
    446474    fprintf(pOutput, "\n%skmk built-in command statistics:\n", pszPrefix);
    447475    for (i = 0; i < cEntries; i++)
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette