Changeset 4549:f31162fefe01 in nginx


Ignore:
Timestamp:
03/21/12 13:58:51 (8 years ago)
Author:
Ruslan Ermilov <ru@…>
Branch:
default
Phase:
public
Convert:
svn:c3fe7df1-7212-e011-8a91-001109144009/trunk@4550
Message:

worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.

Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • auto/os/freebsd

    r4412 r4549  
    135135    fi
    136136fi
     137
     138
     139# cpuset_setaffinity()
     140
     141if [ $version -ge 701000 ]; then
     142    echo " + cpuset_setaffinity() found"
     143    have=NGX_HAVE_CPUSET_SETAFFINITY . auto/have
     144fi
  • auto/os/linux

    r4543 r4549  
    129129ngx_feature_path=
    130130ngx_feature_libs=
    131 ngx_feature_test="long mask = 0;
    132                   sched_setaffinity(0, 32, (cpu_set_t *) &mask)"
     131ngx_feature_test="cpu_set_t mask;
     132                  CPU_ZERO(&mask);
     133                  sched_setaffinity(0, sizeof(cpu_set_t), &mask)"
    133134. auto/feature
    134135
  • auto/sources

    r4412 r4549  
    146146            src/os/unix/ngx_shmem.h \
    147147            src/os/unix/ngx_process.h \
     148            src/os/unix/ngx_setaffinity.h \
    148149            src/os/unix/ngx_setproctitle.h \
    149150            src/os/unix/ngx_atomic.h \
     
    180181            src/os/unix/ngx_process.c \
    181182            src/os/unix/ngx_daemon.c \
     183            src/os/unix/ngx_setaffinity.c \
    182184            src/os/unix/ngx_setproctitle.c \
    183185            src/os/unix/ngx_posix_init.c \
  • src/core/nginx.c

    r4412 r4549  
    984984    ngx_conf_init_value(ccf->debug_points, 0);
    985985
    986 #if (NGX_HAVE_SCHED_SETAFFINITY)
     986#if (NGX_HAVE_CPU_AFFINITY)
    987987
    988988    if (ccf->cpu_affinity_n
     
    991991    {
    992992        ngx_log_error(NGX_LOG_WARN, cycle->log, 0,
    993                       "number of the \"worker_processes\" is not equal to "
    994                       "the number of the \"worker_cpu_affinity\" mask, "
     993                      "the number of \"worker_processes\" is not equal to "
     994                      "the number of \"worker_cpu_affinity\" masks, "
    995995                      "using last mask for remaining worker processes");
    996996    }
     
    12431243ngx_set_cpu_affinity(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
    12441244{
    1245 #if (NGX_HAVE_SCHED_SETAFFINITY)
     1245#if (NGX_HAVE_CPU_AFFINITY)
    12461246    ngx_core_conf_t  *ccf = conf;
    12471247
    12481248    u_char            ch;
    1249     u_long           *mask;
     1249    uint64_t         *mask;
    12501250    ngx_str_t        *value;
    12511251    ngx_uint_t        i, n;
     
    12551255    }
    12561256
    1257     mask = ngx_palloc(cf->pool, (cf->args->nelts - 1) * sizeof(long));
     1257    mask = ngx_palloc(cf->pool, (cf->args->nelts - 1) * sizeof(uint64_t));
    12581258    if (mask == NULL) {
    12591259        return NGX_CONF_ERROR;
     
    12671267    for (n = 1; n < cf->args->nelts; n++) {
    12681268
    1269         if (value[n].len > 32) {
     1269        if (value[n].len > 64) {
    12701270            ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
    1271                          "\"worker_cpu_affinity\" supports up to 32 CPU only");
     1271                         "\"worker_cpu_affinity\" supports up to 64 CPUs only");
    12721272            return NGX_CONF_ERROR;
    12731273        }
     
    13121312
    13131313
    1314 u_long
     1314uint64_t
    13151315ngx_get_cpu_affinity(ngx_uint_t n)
    13161316{
  • src/core/ngx_cycle.h

    r4412 r4549  
    8787
    8888     ngx_uint_t               cpu_affinity_n;
    89      u_long                  *cpu_affinity;
     89     uint64_t                *cpu_affinity;
    9090
    9191     char                    *username;
     
    125125char **ngx_set_environment(ngx_cycle_t *cycle, ngx_uint_t *last);
    126126ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv);
    127 u_long ngx_get_cpu_affinity(ngx_uint_t n);
     127uint64_t ngx_get_cpu_affinity(ngx_uint_t n);
    128128ngx_shm_zone_t *ngx_shared_memory_add(ngx_conf_t *cf, ngx_str_t *name,
    129129    size_t size, void *tag);
  • src/os/unix/ngx_process.h

    r4412 r4549  
    1010
    1111
     12#include <ngx_setaffinity.h>
    1213#include <ngx_setproctitle.h>
    1314
  • src/os/unix/ngx_process_cycle.c

    r4500 r4549  
    6363
    6464
    65 u_long         cpu_affinity;
     65uint64_t       cpu_affinity;
    6666static u_char  master_process[] = "master process";
    6767
     
    914914    }
    915915
    916 #if (NGX_HAVE_SCHED_SETAFFINITY)
    917 
    918916    if (cpu_affinity) {
    919         ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0,
    920                       "sched_setaffinity(0x%08Xl)", cpu_affinity);
    921 
    922         if (sched_setaffinity(0, sizeof(cpu_affinity),
    923                               (cpu_set_t *) &cpu_affinity)
    924             == -1)
    925         {
    926             ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
    927                           "sched_setaffinity(0x%08Xl) failed", cpu_affinity);
    928         }
    929     }
    930 
    931 #endif
     917        ngx_setaffinity(cpu_affinity, cycle->log);
     918    }
    932919
    933920#if (NGX_HAVE_PR_SET_DUMPABLE)
Note: See TracChangeset for help on using the changeset viewer.