Re: [PATCH] Add support cache line size for Hygon Dhyana CPU

2019-05-08 Thread Jinke Fan
Hello Maxim,

On 2019/5/9 0:10, Maxim Dounin wrote:
> Hello!
> 
> On Tue, May 07, 2019 at 07:25:59AM +, Jinke Fan wrote:
> 
>> # HG changeset patch
>> # User Fanjinke 
>> # Date 1557209225 -28800
>> #  Tue May 07 14:07:05 2019 +0800
>> # Node ID 9bc6da16b217ce2c5fc63048a705c2b3195d3bb7
>> # Parent  16a1adadf43751f59257ba419f6bacd530dd19d3
>> Add support cache line size for Hygon Dhyana CPU
>>
>> Background:
>> Chengdu Haiguang IC Design Co., Ltd (Hygon) is a Joint Venture between
>> AMD and Haiguang Information Technology Co.,Ltd., aims at providing high
>> performance x86 processor for China server market. Its first generation
>> processor codename is Dhyana, which originates from AMD technology and
>> shares most of the architecture with AMD's family 17h, but with different
>> CPU Vendor ID("HygonGenuine")/Family series number(Family 18h).
>>
>> diff -r 16a1adadf437 -r 9bc6da16b217 src/core/ngx_cpuinfo.c
>> --- a/src/core/ngx_cpuinfo.c Wed Apr 24 16:38:56 2019 +0300
>> +++ b/src/core/ngx_cpuinfo.c Tue May 07 14:07:05 2019 +0800
>> @@ -124,6 +124,8 @@
>>
>> } else if (ngx_strcmp(vendor, "AuthenticAMD") == 0) {
>> ngx_cacheline_size = 64;
>> +} else if (ngx_strcmp(vendor, "HygonGenuine") == 0) {
>> +ngx_cacheline_size = 64;
>> }
>> }
>>
> 
> Thank you for the patch.
> 
> Starting with nginx 1.13.8 this should already work out of the box
> on systems with sysconf(_SC_LEVEL1_DCACHE_LINESIZE) - that is, at
> least on all Linux systems - as long as the processor is supported
> by OS.  Also, the default is 64 anyway on 64-bit platforms.
> 

Thank you so much for viewing the patch.

sysconf(_SC_LEVEL1_DCACHE_LINESIZE) support Hygon CPU since glibc-2.29,
so,before glibc-2.29 sysconf(_SC_LEVEL1_DCACHE_LINESIZE) will return
zero.

ngx_cacheline_size = NGX_CPU_CACHE_LINE;

Yes, actually, the NGX_CPU_CACHE_LINE is 64 on Hygon platform .

Best Regards!
Jinke.

___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


Slice Module behavior over SSL

2019-05-08 Thread Carey Gister
Hi,

I noticed that if I configure a server to use the slice module it will happily 
read slices of the appropriate size as fast as the upstream server can deliver 
them.

However, if I configure the same server to run over SSL it requests the slices 
at a rate consonant with the speed with which the my client application is 
consuming the data -- in my case about 4MB per second.

This behavior can be easily confirmed from my server access logs and I can 
provide a sample configuration file.

Can anyone explain this behavior?

Carey Gister


___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel

[njs] Fixed arrays expansion.

2019-05-08 Thread Valentin Bartenev
details:   https://hg.nginx.org/njs/rev/8fe38b9f8a94
branches:  
changeset: 960:8fe38b9f8a94
user:  Valentin Bartenev 
date:  Wed May 08 19:09:10 2019 +0300
description:
Fixed arrays expansion.

There were two problems with njs_array_expand():

 1. It checked that the requred size with the appended elements wasn't bigger
then the array size and then did nothing.  If there were elements removed
from the beggining (by shift() operation), then "size <= array->size" can
be true even if there wasn't enought free space after the array.

 2. After allocating more space to prepend elements, it set array->size without
counting those elements.

Probably, the original idea was to decrement array->size while removing
elements from the beginning, but it wasn't done right.  Even if so, the
new version of the function looks cleaner.

This closes #152 and closes #153 issues on Github.

diffstat:

 njs/njs_array.c  |  22 --
 njs/test/njs_unit_test.c |   3 +++
 2 files changed, 15 insertions(+), 10 deletions(-)

diffs (69 lines):

diff -r cb9cbb358a8b -r 8fe38b9f8a94 njs/njs_array.c
--- a/njs/njs_array.c   Wed May 08 19:09:10 2019 +0300
+++ b/njs/njs_array.c   Wed May 08 19:09:10 2019 +0300
@@ -214,15 +214,19 @@ njs_ret_t
 njs_array_expand(njs_vm_t *vm, njs_array_t *array, uint32_t prepend,
 uint32_t append)
 {
+uint32_t free_before, free_after;
 uint64_t size;
 njs_value_t  *start, *old;
 
-size = (uint64_t) append + array->length;
-
-if (nxt_fast_path(size <= array->size && prepend == 0)) {
+free_before = array->start - array->data;
+free_after = array->size - array->length - free_before;
+
+if (nxt_fast_path(free_before >= prepend && free_after >= append)) {
 return NXT_OK;
 }
 
+size = (uint64_t) prepend + array->length + append;
+
 if (size < 16) {
 size *= 2;
 
@@ -230,12 +234,12 @@ njs_array_expand(njs_vm_t *vm, njs_array
 size += size / 2;
 }
 
-if (nxt_slow_path((prepend + size) > NJS_ARRAY_MAX_LENGTH)) {
+if (nxt_slow_path(size > NJS_ARRAY_MAX_LENGTH)) {
 goto memory_error;
 }
 
 start = nxt_mp_align(vm->mem_pool, sizeof(njs_value_t),
- (prepend + size) * sizeof(njs_value_t));
+ size * sizeof(njs_value_t));
 if (nxt_slow_path(start == NULL)) {
 goto memory_error;
 }
@@ -728,11 +732,9 @@ njs_array_prototype_unshift(njs_vm_t *vm
 n = nargs - 1;
 
 if (n != 0) {
-if ((intptr_t) n > (array->start - array->data)) {
-ret = njs_array_expand(vm, array, n, 0);
-if (nxt_slow_path(ret != NXT_OK)) {
-return ret;
-}
+ret = njs_array_expand(vm, array, n, 0);
+if (nxt_slow_path(ret != NXT_OK)) {
+return ret;
 }
 
 array->length += n;
diff -r cb9cbb358a8b -r 8fe38b9f8a94 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c  Wed May 08 19:09:10 2019 +0300
+++ b/njs/test/njs_unit_test.c  Wed May 08 19:09:10 2019 +0300
@@ -3730,6 +3730,9 @@ static njs_unit_test_t  njs_test[] =
  "len +' '+ a +' '+ a.shift()"),
   nxt_string("5 3,4,5,1,2 3") },
 
+{ nxt_string("var a=[0], n = 64; while(--n) {a.push(n); a.shift()}; a"),
+  nxt_string("1") },
+
 { nxt_string("var a = []; a.splice()"),
   nxt_string("") },
 
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Better name for append elements count in njs_array_expand().

2019-05-08 Thread Valentin Bartenev
details:   https://hg.nginx.org/njs/rev/4ed09499a560
branches:  
changeset: 958:4ed09499a560
user:  Valentin Bartenev 
date:  Wed May 08 19:09:10 2019 +0300
description:
Better name for append elements count in njs_array_expand().

No functional changes.

diffstat:

 njs/njs_array.c |  4 ++--
 njs/njs_array.h |  2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diffs (30 lines):

diff -r ff76f83fc49a -r 4ed09499a560 njs/njs_array.c
--- a/njs/njs_array.c   Tue May 07 20:41:07 2019 +0300
+++ b/njs/njs_array.c   Wed May 08 19:09:10 2019 +0300
@@ -212,12 +212,12 @@ njs_array_string_add(njs_vm_t *vm, njs_a
 
 njs_ret_t
 njs_array_expand(njs_vm_t *vm, njs_array_t *array, uint32_t prepend,
-uint32_t new_size)
+uint32_t append)
 {
 uint64_t size;
 njs_value_t  *start, *old;
 
-size = (uint64_t) new_size + array->length;
+size = (uint64_t) append + array->length;
 
 if (nxt_fast_path(size <= array->size && prepend == 0)) {
 return NXT_OK;
diff -r ff76f83fc49a -r 4ed09499a560 njs/njs_array.h
--- a/njs/njs_array.h   Tue May 07 20:41:07 2019 +0300
+++ b/njs/njs_array.h   Wed May 08 19:09:10 2019 +0300
@@ -20,7 +20,7 @@ njs_ret_t njs_array_add(njs_vm_t *vm, nj
 njs_ret_t njs_array_string_add(njs_vm_t *vm, njs_array_t *array,
 const u_char *start, size_t size, size_t length);
 njs_ret_t njs_array_expand(njs_vm_t *vm, njs_array_t *array, uint32_t prepend,
-uint32_t size);
+uint32_t append);
 njs_ret_t njs_array_constructor(njs_vm_t *vm, njs_value_t *args,
 nxt_uint_t nargs, njs_index_t unused);
 
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Simplified check for array length limit in njs_array_expand().

2019-05-08 Thread Valentin Bartenev
details:   https://hg.nginx.org/njs/rev/cb9cbb358a8b
branches:  
changeset: 959:cb9cbb358a8b
user:  Valentin Bartenev 
date:  Wed May 08 19:09:10 2019 +0300
description:
Simplified check for array length limit in njs_array_expand().

No functional changes.

diffstat:

 njs/njs_array.c |  2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diffs (12 lines):

diff -r 4ed09499a560 -r cb9cbb358a8b njs/njs_array.c
--- a/njs/njs_array.c   Wed May 08 19:09:10 2019 +0300
+++ b/njs/njs_array.c   Wed May 08 19:09:10 2019 +0300
@@ -230,7 +230,7 @@ njs_array_expand(njs_vm_t *vm, njs_array
 size += size / 2;
 }
 
-if (nxt_slow_path(((prepend + size) * sizeof(njs_value_t)) >= UINT32_MAX)) 
{
+if (nxt_slow_path((prepend + size) > NJS_ARRAY_MAX_LENGTH)) {
 goto memory_error;
 }
 
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


Re: [PATCH] Add support cache line size for Hygon Dhyana CPU

2019-05-08 Thread Maxim Dounin
Hello!

On Tue, May 07, 2019 at 07:25:59AM +, Jinke Fan wrote:

> # HG changeset patch
> # User Fanjinke 
> # Date 1557209225 -28800
> #  Tue May 07 14:07:05 2019 +0800
> # Node ID 9bc6da16b217ce2c5fc63048a705c2b3195d3bb7
> # Parent  16a1adadf43751f59257ba419f6bacd530dd19d3
> Add support cache line size for Hygon Dhyana CPU
> 
> Background:
> Chengdu Haiguang IC Design Co., Ltd (Hygon) is a Joint Venture between
> AMD and Haiguang Information Technology Co.,Ltd., aims at providing high
> performance x86 processor for China server market. Its first generation
> processor codename is Dhyana, which originates from AMD technology and
> shares most of the architecture with AMD's family 17h, but with different
> CPU Vendor ID("HygonGenuine")/Family series number(Family 18h).
> 
> diff -r 16a1adadf437 -r 9bc6da16b217 src/core/ngx_cpuinfo.c
> --- a/src/core/ngx_cpuinfo.c  Wed Apr 24 16:38:56 2019 +0300
> +++ b/src/core/ngx_cpuinfo.c  Tue May 07 14:07:05 2019 +0800
> @@ -124,6 +124,8 @@
> 
>} else if (ngx_strcmp(vendor, "AuthenticAMD") == 0) {
>ngx_cacheline_size = 64;
> +} else if (ngx_strcmp(vendor, "HygonGenuine") == 0) {
> +ngx_cacheline_size = 64;
>}
>}
> 

Thank you for the patch.

Starting with nginx 1.13.8 this should already work out of the box 
on systems with sysconf(_SC_LEVEL1_DCACHE_LINESIZE) - that is, at 
least on all Linux systems - as long as the processor is supported 
by OS.  Also, the default is 64 anyway on 64-bit platforms.

-- 
Maxim Dounin
http://mdounin.ru/
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel