diff options
author | Igor Sysoev <igor@sysoev.ru> | 2004-06-30 19:30:41 +0400 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2004-06-30 19:30:41 +0400 |
commit | 078d1b2c2263690f2f6b7217b567eeeb525910d0 (patch) | |
tree | dfb82cccd10c3dee8a500506f7692b0445200e5c /src/os/unix | |
parent | 0a94cfd2ae9ca87b4d988b5066f739a3034f3bff (diff) |
nginx-0.0.7-2004-06-30-19:30:41 import
Diffstat (limited to 'src/os/unix')
-rw-r--r-- | src/os/unix/ngx_atomic.h | 90 | ||||
-rw-r--r-- | src/os/unix/ngx_freebsd_init.c | 15 | ||||
-rw-r--r-- | src/os/unix/ngx_os.h | 1 | ||||
-rw-r--r-- | src/os/unix/ngx_posix_init.c | 5 | ||||
-rw-r--r-- | src/os/unix/ngx_process.h | 2 |
5 files changed, 113 insertions, 0 deletions
diff --git a/src/os/unix/ngx_atomic.h b/src/os/unix/ngx_atomic.h new file mode 100644 index 000000000..18d5edac5 --- /dev/null +++ b/src/os/unix/ngx_atomic.h @@ -0,0 +1,90 @@ +#ifndef _NGX_ATOMIC_H_INCLUDED_ +#define _NGX_ATOMIC_H_INCLUDED_ + + +#include <ngx_config.h> +#include <ngx_core.h> + + +#if ( __i386__ || __amd64__ ) + +typedef volatile uint32_t ngx_atomic_t; + +#if (NGX_SMP) +#define NGX_SMP_LOCK "lock;" +#else +#define NGX_SMP_LOCK +#endif + + +static ngx_inline uint32_t ngx_atomic_inc(ngx_atomic_t *value) +{ + uint32_t old; + + __asm__ volatile ( + + NGX_SMP_LOCK + " xaddl %0, %2; " + " incl %0; " + + : "=q" (old) : "0" (1), "m" (*value)); + + return old; +} + + +static ngx_inline uint32_t ngx_atomic_dec(ngx_atomic_t *value) +{ + uint32_t old; + + __asm__ volatile ( + + NGX_SMP_LOCK + " xaddl %0, %1; " + " decl %0; " + + : "=q" (old) : "0" (-1), "m" (*value)); + + return old; +} + + +static ngx_inline uint32_t ngx_atomic_cmp_set(ngx_atomic_t *lock, + ngx_atomic_t old, + ngx_atomic_t set) +{ + uint32_t res; + + __asm__ volatile ( + + NGX_SMP_LOCK + " cmpxchgl %3, %1; " + " setz %%al; " + " movzbl %%al, %0; " + + : "=a" (res) : "m" (*lock), "a" (old), "q" (set)); + + return res; +} + + +#else + +typedef volatile uint32_t ngx_atomic_t; + +/* STUB */ +#define ngx_atomic_inc(x) (*(x))++; +#define ngx_atomic_dec(x) (*(x))--; +#define ngx_atomic_cmp_set(lock, old, set) 1 +/**/ + +#endif + + +void ngx_spinlock(ngx_atomic_t *lock, ngx_uint_t spin); + +#define ngx_trylock(lock) (*(lock) == 0 && ngx_atomic_cmp_set(lock, 0, 1)) +#define ngx_unlock(lock) *(lock) = 0 + + +#endif /* _NGX_ATOMIC_H_INCLUDED_ */ diff --git a/src/os/unix/ngx_freebsd_init.c b/src/os/unix/ngx_freebsd_init.c index 35be16412..5addd26a8 100644 --- a/src/os/unix/ngx_freebsd_init.c +++ b/src/os/unix/ngx_freebsd_init.c @@ -8,6 +8,7 @@ char ngx_freebsd_kern_ostype[20]; char ngx_freebsd_kern_osrelease[20]; int ngx_freebsd_kern_osreldate; int ngx_freebsd_hw_ncpu; +int ngx_freebsd_machdep_hlt_logical_cpus; int ngx_freebsd_net_inet_tcp_sendspace; int ngx_freebsd_sendfile_nbytes_bug; int ngx_freebsd_use_tcp_nopush; @@ -42,6 +43,10 @@ sysctl_t sysctls[] = { &ngx_freebsd_hw_ncpu, sizeof(int)}, + {"machdep.hlt_logical_cpus", + &ngx_freebsd_machdep_hlt_logical_cpus, + sizeof(int)}, + {"net.inet.tcp.sendspace", &ngx_freebsd_net_inet_tcp_sendspace, sizeof(int)}, @@ -166,6 +171,10 @@ int ngx_os_init(ngx_log_t *log) == -1) { err = errno; if (err != NGX_ENOENT) { + if (sysctls[i].value == &ngx_freebsd_machdep_hlt_logical_cpus) { + continue; + } + ngx_log_error(NGX_LOG_ALERT, log, err, "sysctlbyname(%s) failed", sysctls[i].name); return NGX_ERROR; @@ -177,5 +186,11 @@ int ngx_os_init(ngx_log_t *log) } } + if (ngx_freebsd_machdep_hlt_logical_cpus) { + ngx_ncpu = ngx_freebsd_hw_ncpu / 2; + } else { + ngx_ncpu = ngx_freebsd_hw_ncpu; + } + return ngx_posix_init(log); } diff --git a/src/os/unix/ngx_os.h b/src/os/unix/ngx_os.h index d9a1a4560..c4da5cdbd 100644 --- a/src/os/unix/ngx_os.h +++ b/src/os/unix/ngx_os.h @@ -47,6 +47,7 @@ ngx_chain_t *ngx_writev_chain(ngx_connection_t *c, ngx_chain_t *in, extern ngx_os_io_t ngx_os_io; +extern int ngx_ncpu; extern int ngx_max_sockets; extern int ngx_inherited_nonblocking; diff --git a/src/os/unix/ngx_posix_init.c b/src/os/unix/ngx_posix_init.c index f94ffffc6..7498ae609 100644 --- a/src/os/unix/ngx_posix_init.c +++ b/src/os/unix/ngx_posix_init.c @@ -3,6 +3,7 @@ #include <ngx_core.h> +int ngx_ncpu; int ngx_max_sockets; int ngx_inherited_nonblocking; @@ -84,6 +85,10 @@ int ngx_posix_init(ngx_log_t *log) ngx_pagesize = getpagesize(); + if (ngx_ncpu == 0) { + ngx_ncpu = 1; + } + for (sig = signals; sig->signo != 0; sig++) { ngx_memzero(&sa, sizeof(struct sigaction)); sa.sa_handler = sig->handler; diff --git a/src/os/unix/ngx_process.h b/src/os/unix/ngx_process.h index ccea40db7..66ef38d57 100644 --- a/src/os/unix/ngx_process.h +++ b/src/os/unix/ngx_process.h @@ -49,6 +49,8 @@ ngx_pid_t ngx_execute(ngx_cycle_t *cycle, ngx_exec_ctx_t *ctx); void ngx_process_get_status(void); void ngx_close_channel(ngx_fd_t *fd, ngx_log_t *log); +#define ngx_sched_yield() sched_yield() + extern ngx_pid_t ngx_pid; extern ngx_socket_t ngx_channel; |