Ticket #1437: SO_INCOMING_CPU.patch

File SO_INCOMING_CPU.patch, 1.3 KB (added by vadimjunk@…, 9 years ago)
  • src/core/ngx_connection.c

    a b  
    952952        }
    953953
    954954#endif
     955
     956#if (NGX_HAVE_SCHED_SETAFFINITY) && (SO_INCOMING_CPU)
     957        {
     958            ngx_cpuset_t *cpu_affinity = ngx_get_cpu_affinity(ls[i].worker);
     959            ngx_int_t cpu;
     960            socklen_t clen = sizeof(cpu);
     961            for (cpu = 0; cpu < CPU_SETSIZE; cpu++) {
     962                if (CPU_ISSET(cpu, cpu_affinity)) {
     963                    ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0,
     964                                  "setsockopt(SO_INCOMING_CPU): using cpu #%ui"
     965                                  " for socket with worker #%ui", cpu, ls[i].worker);
     966                    if (setsockopt(ls[i].fd, SOL_SOCKET, SO_INCOMING_CPU, &cpu, clen)
     967                        == -1)
     968                    {
     969                        ngx_log_error(NGX_LOG_WARN, cycle->log, ngx_socket_errno,
     970                            "setsockopt(SO_INCOMING_CPU) "
     971                            "for worker socket #%ui failed, ignored",
     972                            cpu);
     973                     
     974                    }
     975                    break;
     976                }
     977            }
     978                   
     979        }
     980#endif
    955981    }
    956982
    957983    return;