Re: [PHP-DEV] RFC - Zend VM Pause API

2017-11-05 Thread Haitao Lv
After discussion with Dmitry, I update my RFC. The RFC url is here

https://wiki.php.net/rfc/zend-vm-pause-api

And I propose to introduce a new interrupt type to make vm pause-and-return, 
not pause-and-continue.

As mentioned by Dmitry, features like Fiber could be implemented by current 
vm_interrupt implementation, theoretically. By using it, even init a function 
call will need to make our own op array.

So I propose this patch.

Thank you.


> On 1 Nov 2017, at 17:13, Haitao Lv  wrote:
> 
> Would it proper to introduce the following path?
> 
> diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h
> index 9bed9f86bb..cf0935df74 100644
> --- a/Zend/zend_vm_def.h
> +++ b/Zend/zend_vm_def.h
> @@ -8920,13 +8920,19 @@ ZEND_VM_DEFINE_OP(137, ZEND_OP_DATA);
> 
> ZEND_VM_HELPER(zend_interrupt_helper, ANY, ANY)
> {
> +   int8_t interrupt_type = EG(vm_interrupt);
> +
>EG(vm_interrupt) = 0;
>if (EG(timed_out)) {
>zend_timeout(0);
>} else if (zend_interrupt_function) {
>SAVE_OPLINE();
>zend_interrupt_function(execute_data);
> -   ZEND_VM_ENTER();
> +   if (interrupt_type == 2) {
> +   ZEND_VM_RETURN();
> +   } else {
> +   ZEND_VM_ENTER();
> +   }
>}
>ZEND_VM_CONTINUE();
> }
> 
>> On 1 Nov 2017, at 16:54, Haitao Lv  wrote:
>> 
>> It seems that set EG(vm_interrupt) to 1 could not stop the vm execution but 
>> only execute the interrupt_function and continue the current execution.
>> 
>> However, my RFC propose to stop the current execution.
>> 
>>> On 1 Nov 2017, at 16:07, Dmitry Stogov  wrote:
>>> 
>>> Hi,
>>> 
>>> It should be possible do similar things using EG(vm_interrupt) and 
>>> zend_interrupt_function() callback (introduced in php-7.1)
>>> ext/pcntl implements asynchronous signal handling using this.
>>> 
>>> Thanks. Dmitry.
>>> From: Haitao Lv 
>>> Sent: Wednesday, November 1, 2017 4:19:07 AM
>>> To: PHP Internals
>>> Subject: [PHP-DEV] RFC - Zend VM Pause API 
>>> 
>>> Hi, internals,
>>> 
>>> I propose to introduce a new zend vm pause api, and here is the RPF
>>> 
>>> https://wiki.php.net/rfc/zend-vm-pause-api 
>>> 
>>> 
>>> Please gave your comment.
>>> 
>>> Thank you.
>>> 
>>> 
>>> 
>>> -- 
>>> PHP Internals - PHP Runtime Development Mailing List
>>> To unsubscribe, visit: http://www.php.net/unsub.php 
>>> 
> 
> 
> 
> 
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php




--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] RFC - Zend VM Pause API

2017-11-01 Thread Dmitry Stogov
I'm not sure, why do you need to exit from the current VM instance.

It should be possible to perform fiber scheduling and VM context switch 
directly in interrupt handler (like in real OS).

VM should handle this out of the box (at least VM interrupts were designed with 
context switch in mind).


In your case, I suppose, part of zend_fiber_resume() should be merged into 
fiber_interrupt_function().

Also you should handle only your own interrupts (like ext/pcntl does checking 
PCNTL_G(pending_signals)).


Sorry, I don't have a lot of time to review your sources.

However, the implementation is really interesting, and I'm glad, someone is 
working on this.


Thanks. Dmitry.


From: Haitao Lv <i...@lvht.net>
Sent: Wednesday, November 1, 2017 12:45:13 PM
To: Dmitry Stogov
Cc: PHP Internals
Subject: Re: [PHP-DEV] RFC - Zend VM Pause API

To make the discussion more detailed, please allow me to offer my 
implementation of use land coroutine(Fiber).

https://github.com/php/php-src/compare/master...fiberphp:fiber-ext?expand=1


> On 1 Nov 2017, at 17:32, Haitao Lv <i...@lvht.net> wrote:
>
> Suppose we have a internal Coroutine class and it has a resume() method.
>
> In order to resume the coroutine, we have to call the resume() function.
>
> As the resume function is a internal method defined in c, we need call
>
> zend_execute_ex(backuped_execute_data)
>
> to resume the zend execution.
>
> If we need to pause the coroutine, we set the EG(vm_interrupt) and 
> interrupt_function,
> and switch the execute data and stack. The zend vm will execute the old 
> online.
>
> However, we will never see the resume() method returned and never get its 
> return value.
>
>> On 1 Nov 2017, at 17:14, Dmitry Stogov <dmi...@zend.com> wrote:
>>
>> after zend_interrupt_function() callback VM continues execution using 
>> EG(current_execute_data).
>> callback may modify it in any way (e.g. unwind stack, or switch to another 
>> co-routine or continuation).
>>
>> Thanks. Dmitry.
>> From: Haitao Lv <i...@lvht.net>
>> Sent: Wednesday, November 1, 2017 11:54:54 AM
>> To: Dmitry Stogov
>> Cc: PHP Internals
>> Subject: Re: [PHP-DEV] RFC - Zend VM Pause API
>>
>> It seems that set EG(vm_interrupt) to 1 could not stop the vm execution but 
>> only execute the interrupt_function and continue the current execution.
>>
>> However, my RFC propose to stop the current execution.
>>
>>> On 1 Nov 2017, at 16:07, Dmitry Stogov <dmi...@zend.com> wrote:
>>>
>>> Hi,
>>>
>>> It should be possible do similar things using EG(vm_interrupt) and 
>>> zend_interrupt_function() callback (introduced in php-7.1)
>>> ext/pcntl implements asynchronous signal handling using this.
>>>
>>> Thanks. Dmitry.
>>> From: Haitao Lv <i...@lvht.net>
>>> Sent: Wednesday, November 1, 2017 4:19:07 AM
>>> To: PHP Internals
>>> Subject: [PHP-DEV] RFC - Zend VM Pause API
>>>
>>> Hi, internals,
>>>
>>> I propose to introduce a new zend vm pause api, and here is the RPF
>>>
>>> https://wiki.php.net/rfc/zend-vm-pause-api
>>>
>>> Please gave your comment.
>>>
>>> Thank you.
>>>
>>>
>>>
>>> --
>>> PHP Internals - PHP Runtime Development Mailing List
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
>
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>





Re: [PHP-DEV] RFC - Zend VM Pause API

2017-11-01 Thread Haitao Lv
To make the discussion more detailed, please allow me to offer my 
implementation of use land coroutine(Fiber).

https://github.com/php/php-src/compare/master...fiberphp:fiber-ext?expand=1


> On 1 Nov 2017, at 17:32, Haitao Lv <i...@lvht.net> wrote:
> 
> Suppose we have a internal Coroutine class and it has a resume() method.
> 
> In order to resume the coroutine, we have to call the resume() function.
> 
> As the resume function is a internal method defined in c, we need call
> 
> zend_execute_ex(backuped_execute_data)
> 
> to resume the zend execution.
> 
> If we need to pause the coroutine, we set the EG(vm_interrupt) and 
> interrupt_function,
> and switch the execute data and stack. The zend vm will execute the old 
> online.
> 
> However, we will never see the resume() method returned and never get its 
> return value.
> 
>> On 1 Nov 2017, at 17:14, Dmitry Stogov <dmi...@zend.com> wrote:
>> 
>> after zend_interrupt_function() callback VM continues execution using 
>> EG(current_execute_data).
>> callback may modify it in any way (e.g. unwind stack, or switch to another 
>> co-routine or continuation).
>> 
>> Thanks. Dmitry.
>> From: Haitao Lv <i...@lvht.net>
>> Sent: Wednesday, November 1, 2017 11:54:54 AM
>> To: Dmitry Stogov
>> Cc: PHP Internals
>> Subject: Re: [PHP-DEV] RFC - Zend VM Pause API 
>> 
>> It seems that set EG(vm_interrupt) to 1 could not stop the vm execution but 
>> only execute the interrupt_function and continue the current execution.
>> 
>> However, my RFC propose to stop the current execution.
>> 
>>> On 1 Nov 2017, at 16:07, Dmitry Stogov <dmi...@zend.com> wrote:
>>> 
>>> Hi,
>>> 
>>> It should be possible do similar things using EG(vm_interrupt) and 
>>> zend_interrupt_function() callback (introduced in php-7.1)
>>> ext/pcntl implements asynchronous signal handling using this.
>>> 
>>> Thanks. Dmitry.
>>> From: Haitao Lv <i...@lvht.net>
>>> Sent: Wednesday, November 1, 2017 4:19:07 AM
>>> To: PHP Internals
>>> Subject: [PHP-DEV] RFC - Zend VM Pause API 
>>> 
>>> Hi, internals,
>>> 
>>> I propose to introduce a new zend vm pause api, and here is the RPF
>>> 
>>> https://wiki.php.net/rfc/zend-vm-pause-api
>>> 
>>> Please gave your comment.
>>> 
>>> Thank you.
>>> 
>>> 
>>> 
>>> -- 
>>> PHP Internals - PHP Runtime Development Mailing List
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>> 
>> 
> 
> 
> 
> 
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
> 




--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] RFC - Zend VM Pause API

2017-11-01 Thread Haitao Lv
Suppose we have a internal Coroutine class and it has a resume() method.

In order to resume the coroutine, we have to call the resume() function.

As the resume function is a internal method defined in c, we need call

zend_execute_ex(backuped_execute_data)

to resume the zend execution.

If we need to pause the coroutine, we set the EG(vm_interrupt) and 
interrupt_function,
and switch the execute data and stack. The zend vm will execute the old online.

However, we will never see the resume() method returned and never get its 
return value.

> On 1 Nov 2017, at 17:14, Dmitry Stogov <dmi...@zend.com> wrote:
> 
> after zend_interrupt_function() callback VM continues execution using 
> EG(current_execute_data).
> callback may modify it in any way (e.g. unwind stack, or switch to another 
> co-routine or continuation).
> 
> Thanks. Dmitry.
> From: Haitao Lv <i...@lvht.net>
> Sent: Wednesday, November 1, 2017 11:54:54 AM
> To: Dmitry Stogov
> Cc: PHP Internals
> Subject: Re: [PHP-DEV] RFC - Zend VM Pause API 
>  
> It seems that set EG(vm_interrupt) to 1 could not stop the vm execution but 
> only execute the interrupt_function and continue the current execution.
> 
> However, my RFC propose to stop the current execution.
> 
>> On 1 Nov 2017, at 16:07, Dmitry Stogov <dmi...@zend.com> wrote:
>> 
>> Hi,
>> 
>> It should be possible do similar things using EG(vm_interrupt) and 
>> zend_interrupt_function() callback (introduced in php-7.1)
>> ext/pcntl implements asynchronous signal handling using this.
>> 
>> Thanks. Dmitry.
>> From: Haitao Lv <i...@lvht.net>
>> Sent: Wednesday, November 1, 2017 4:19:07 AM
>> To: PHP Internals
>> Subject: [PHP-DEV] RFC - Zend VM Pause API 
>>  
>> Hi, internals,
>> 
>> I propose to introduce a new zend vm pause api, and here is the RPF
>> 
>> https://wiki.php.net/rfc/zend-vm-pause-api
>> 
>> Please gave your comment.
>> 
>> Thank you.
>> 
>> 
>> 
>> -- 
>> PHP Internals - PHP Runtime Development Mailing List
>> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 




--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] RFC - Zend VM Pause API

2017-11-01 Thread Dmitry Stogov
or just change execute_data->opline...


From: Dmitry Stogov
Sent: Wednesday, November 1, 2017 12:14:22 PM
To: Haitao Lv
Cc: PHP Internals
Subject: Re: [PHP-DEV] RFC - Zend VM Pause API


after zend_interrupt_function() callback VM continues execution using 
EG(current_execute_data).

callback may modify it in any way (e.g. unwind stack, or switch to another 
co-routine or continuation).


Thanks. Dmitry.


From: Haitao Lv <i...@lvht.net>
Sent: Wednesday, November 1, 2017 11:54:54 AM
To: Dmitry Stogov
Cc: PHP Internals
Subject: Re: [PHP-DEV] RFC - Zend VM Pause API

It seems that set EG(vm_interrupt) to 1 could not stop the vm execution but 
only execute the interrupt_function and continue the current execution.

However, my RFC propose to stop the current execution.

On 1 Nov 2017, at 16:07, Dmitry Stogov 
<dmi...@zend.com<mailto:dmi...@zend.com>> wrote:

Hi,

It should be possible do similar things using EG(vm_interrupt) and 
zend_interrupt_function() callback (introduced in php-7.1)
ext/pcntl implements asynchronous signal handling using this.

Thanks. Dmitry.

From: Haitao Lv <i...@lvht.net<mailto:i...@lvht.net>>
Sent: Wednesday, November 1, 2017 4:19:07 AM
To: PHP Internals
Subject: [PHP-DEV] RFC - Zend VM Pause API

Hi, internals,

I propose to introduce a new zend vm pause api, and here is the RPF

https://wiki.php.net/rfc/zend-vm-pause-api

Please gave your comment.

Thank you.



--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] RFC - Zend VM Pause API

2017-11-01 Thread Dmitry Stogov
after zend_interrupt_function() callback VM continues execution using 
EG(current_execute_data).

callback may modify it in any way (e.g. unwind stack, or switch to another 
co-routine or continuation).


Thanks. Dmitry.


From: Haitao Lv <i...@lvht.net>
Sent: Wednesday, November 1, 2017 11:54:54 AM
To: Dmitry Stogov
Cc: PHP Internals
Subject: Re: [PHP-DEV] RFC - Zend VM Pause API

It seems that set EG(vm_interrupt) to 1 could not stop the vm execution but 
only execute the interrupt_function and continue the current execution.

However, my RFC propose to stop the current execution.

On 1 Nov 2017, at 16:07, Dmitry Stogov 
<dmi...@zend.com<mailto:dmi...@zend.com>> wrote:

Hi,

It should be possible do similar things using EG(vm_interrupt) and 
zend_interrupt_function() callback (introduced in php-7.1)
ext/pcntl implements asynchronous signal handling using this.

Thanks. Dmitry.

From: Haitao Lv <i...@lvht.net<mailto:i...@lvht.net>>
Sent: Wednesday, November 1, 2017 4:19:07 AM
To: PHP Internals
Subject: [PHP-DEV] RFC - Zend VM Pause API

Hi, internals,

I propose to introduce a new zend vm pause api, and here is the RPF

https://wiki.php.net/rfc/zend-vm-pause-api

Please gave your comment.

Thank you.



--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] RFC - Zend VM Pause API

2017-11-01 Thread Haitao Lv
Would it proper to introduce the following path?

diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h
index 9bed9f86bb..cf0935df74 100644
--- a/Zend/zend_vm_def.h
+++ b/Zend/zend_vm_def.h
@@ -8920,13 +8920,19 @@ ZEND_VM_DEFINE_OP(137, ZEND_OP_DATA);

 ZEND_VM_HELPER(zend_interrupt_helper, ANY, ANY)
 {
+   int8_t interrupt_type = EG(vm_interrupt);
+
EG(vm_interrupt) = 0;
if (EG(timed_out)) {
zend_timeout(0);
} else if (zend_interrupt_function) {
SAVE_OPLINE();
zend_interrupt_function(execute_data);
-   ZEND_VM_ENTER();
+   if (interrupt_type == 2) {
+   ZEND_VM_RETURN();
+   } else {
+   ZEND_VM_ENTER();
+   }
}
ZEND_VM_CONTINUE();
 }

> On 1 Nov 2017, at 16:54, Haitao Lv  wrote:
> 
> It seems that set EG(vm_interrupt) to 1 could not stop the vm execution but 
> only execute the interrupt_function and continue the current execution.
> 
> However, my RFC propose to stop the current execution.
> 
>> On 1 Nov 2017, at 16:07, Dmitry Stogov  wrote:
>> 
>> Hi,
>> 
>> It should be possible do similar things using EG(vm_interrupt) and 
>> zend_interrupt_function() callback (introduced in php-7.1)
>> ext/pcntl implements asynchronous signal handling using this.
>> 
>> Thanks. Dmitry.
>> From: Haitao Lv 
>> Sent: Wednesday, November 1, 2017 4:19:07 AM
>> To: PHP Internals
>> Subject: [PHP-DEV] RFC - Zend VM Pause API 
>> 
>> Hi, internals,
>> 
>> I propose to introduce a new zend vm pause api, and here is the RPF
>> 
>> https://wiki.php.net/rfc/zend-vm-pause-api 
>> 
>> 
>> Please gave your comment.
>> 
>> Thank you.
>> 
>> 
>> 
>> -- 
>> PHP Internals - PHP Runtime Development Mailing List
>> To unsubscribe, visit: http://www.php.net/unsub.php 
>> 




--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] RFC - Zend VM Pause API

2017-11-01 Thread Haitao Lv
It seems that set EG(vm_interrupt) to 1 could not stop the vm execution but 
only execute the interrupt_function and continue the current execution.

However, my RFC propose to stop the current execution.

> On 1 Nov 2017, at 16:07, Dmitry Stogov  wrote:
> 
> Hi,
> 
> It should be possible do similar things using EG(vm_interrupt) and 
> zend_interrupt_function() callback (introduced in php-7.1)
> ext/pcntl implements asynchronous signal handling using this.
> 
> Thanks. Dmitry.
> From: Haitao Lv 
> Sent: Wednesday, November 1, 2017 4:19:07 AM
> To: PHP Internals
> Subject: [PHP-DEV] RFC - Zend VM Pause API 
>  
> Hi, internals,
> 
> I propose to introduce a new zend vm pause api, and here is the RPF
> 
> https://wiki.php.net/rfc/zend-vm-pause-api 
> 
> 
> Please gave your comment.
> 
> Thank you.
> 
> 
> 
> -- 
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php 
> 


Re: [PHP-DEV] RFC - Zend VM Pause API

2017-11-01 Thread Dmitry Stogov
Hi,


It should be possible do similar things using EG(vm_interrupt) and 
zend_interrupt_function() callback (introduced in php-7.1)

ext/pcntl implements asynchronous signal handling using this.


Thanks. Dmitry.


From: Haitao Lv 
Sent: Wednesday, November 1, 2017 4:19:07 AM
To: PHP Internals
Subject: [PHP-DEV] RFC - Zend VM Pause API

Hi, internals,

I propose to introduce a new zend vm pause api, and here is the RPF

https://wiki.php.net/rfc/zend-vm-pause-api

Please gave your comment.

Thank you.



--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php