Skip to contentSkip to conversation

SPDK Thread and Nvmf QPair migration

SPDK Hari Kadayam 2 participants 7 messages May 16, 2020 – May 21, 2020

lore
Share & tools
lore

Hari Kadayam

author
#0 lore raw

We are trying to add SPDK to our existing async based framework and would like to do at spdk_thread level instead of reactor. I think we can run multiple spdk_threads in a single system thread by polling each thread in a round robin fashion. However, how do we move the spdk_thread into a different system thread, should we pause and pass the object to other thread and resume? What happens to the NVMf poll group which is associated in that thread. Are they movable to a different system thread? My understanding is that nvmf q-pair once associated needs to stick that poll group. Is that the same for system threads as well (meaning does it use any thread local variables) which stops them from moving to a different thread.

Thanks

#1 lore raw

Hi Hari,

About migrating a SPDK thread to a different system thread, we support spdk_set_cpumask() API now. spdk_set_cpumask() requires the event framework layer to implment SPDK_THREAD_OP_RESCHED operation.

spdk_set_cpumask() is similar with Linux sched_setaffinity().

I hope lib/event/reactor.c will give some hint if you don't use reactor but implement your own scheduler.

Even if you use reactor, I admit there is few documentation about this feature. I want to write it though. Besides, SPDK reactor not have dynamic SPDK thread scheduler yet.
So we have to use RPC and do manually SPDK thread migration.

About migrating a qair to a different poll group, NVMf layer does not support it.
One of the primary reason will be that mapping qpair to pollgroup is fixed for RDMA transport, e.g., due to Shared Receive Queue.

Thanks,
Shuhei

________________________________
差出人: Hari Kadayam <harihara.kadayam(a)gmail.com>
送信日時: 2020年5月17日 7:11
宛先: spdk(a)lists.01.org <spdk(a)lists.01.org>
件名: [SPDK] SPDK Thread and Nvmf QPair migration

We are trying to add SPDK to our existing async based framework and would like to do at spdk_thread level instead of reactor. I think we can run multiple spdk_threads in a single system thread by polling each thread in a round robin fashion. However, how do we move the spdk_thread into a different system thread, should we pause and pass the object to other thread and resume? What happens to the NVMf poll group which is associated in that thread. Are they movable to a different system thread? My understanding is that nvmf q-pair once associated needs to stick that poll group. Is that the same for system threads as well (meaning does it use any thread local variables) which stops them from moving to a different thread.

Thanks
_______________________________________________
SPDK mailing list -- spdk(a)lists.01.org
To unsubscribe send an email to spdk-leave(a)lists.01.org

#2 lore raw

Hi Hari,

My work on dynamic SPDK thread scheduling has been suspended due to other higher priority works, but I will restart it once other works have been done.
I will restart it from automatic SPDK thread scheduler by using the current SPDK thread statistics. The target date is not clear yet.

Of course it's very welcome if anyone can do it.

Ben may provide better feedback.

Thanks,
Shuhei

________________________________
差出人: 松本周平 / MATSUMOTO,SHUUHEI <shuhei.matsumoto.xt(a)hitachi.com> 送信日時: 2020年5月18日 7:51
宛先: spdk(a)lists.01.org <spdk(a)lists.01.org>
件名: Re: [SPDK] SPDK Thread and Nvmf QPair migration

Hi Hari,

About migrating a SPDK thread to a different system thread, we support spdk_set_cpumask() API now. spdk_set_cpumask() requires the event framework layer to implment SPDK_THREAD_OP_RESCHED operation.

spdk_set_cpumask() is similar with Linux sched_setaffinity().

I hope lib/event/reactor.c will give some hint if you don't use reactor but implement your own scheduler.

Even if you use reactor, I admit there is few documentation about this feature. I want to write it though. Besides, SPDK reactor not have dynamic SPDK thread scheduler yet.
So we have to use RPC and do manually SPDK thread migration.

About migrating a qair to a different poll group, NVMf layer does not support it.
One of the primary reason will be that mapping qpair to pollgroup is fixed for RDMA transport, e.g., due to Shared Receive Queue.

Thanks,
Shuhei

________________________________
差出人: Hari Kadayam <harihara.kadayam(a)gmail.com>
送信日時: 2020年5月17日 7:11
宛先: spdk(a)lists.01.org <spdk(a)lists.01.org>
件名: [SPDK] SPDK Thread and Nvmf QPair migration

We are trying to add SPDK to our existing async based framework and would like to do at spdk_thread level instead of reactor. I think we can run multiple spdk_threads in a single system thread by polling each thread in a round robin fashion. However, how do we move the spdk_thread into a different system thread, should we pause and pass the object to other thread and resume? What happens to the NVMf poll group which is associated in that thread. Are they movable to a different system thread? My understanding is that nvmf q-pair once associated needs to stick that poll group. Is that the same for system threads as well (meaning does it use any thread local variables) which stops them from moving to a different thread.

Thanks
_______________________________________________
SPDK mailing list -- spdk(a)lists.01.org
To unsubscribe send an email to spdk-leave(a)lists.01.org

#3 lore raw
In reply to Hari Kadayam

Hi Hari,

Quoted 6 lines

-----Original Message-----
From: Hari Kadayam <harihara.kadayam(a)gmail.com>
Sent: Saturday, May 16, 2020 3:11 PM
To: spdk(a)lists.01.org
Subject: [SPDK] SPDK Thread and Nvmf QPair migration

Quoted 10 lines

We are trying to add SPDK to our existing async based framework and would like to do at spdk_thread level instead of reactor. I think we can run multiple spdk_threads in a single system thread by polling each thread in a round robin fashion. However, how do we move the spdk_thread into a different system thread, should we pause and pass the object to other thread and resume? What happens to the NVMf poll group which is associated in that thread. Are they movable to a different system thread? My understanding is that nvmf q-pair once associated needs to stick that poll group. Is that the same for system threads as well (meaning does it use any thread local variables) which stops them from moving to a different thread.

Since you have your own async framework, it's best to not use the SPDK framework (lib/event) like you indicated. You can simply incorporate the SPDK lightweight thread library (lib/thread) directly with your current framework instead. All of the code in the nvmf library only runs within the context of an SPDK lightweight thread (struct spdk_thread). And a lightweight thread only is running when your framework calls spdk_thread_poll on that particular thread. Therefore, if no system thread is currently calling spdk_thread_poll on the lightweight thread in question, you are free to move it to another system thread via message passing or however your framework wants to do it. You do not need any additional coordination at the lib/nvmf level - all of the code associated with that thread will only execute when your framework calls spdk_thread_poll(), so if you don't call that during the move, then nothing is running.

Shuhei and I have been doing some work to dynamically reschedule threads for the applications SPDK ships, which all rely on the SPDK application framework. You can use that code as an example (all in lib/event). But the specifics of how the thread library will need to be integrated into your particular framework depend heavily on the design of your framework. Fortunately the thread library's requirements are very small - a few function callbacks - so I think it'll be a quick task. Certainly in the few instances where we've tried to integrate it with an outside framework, it ended up only requiring ~100 lines of code.

Feel free to ask questions if you hit any issues.

Thanks,
Ben

Quoted 5 lines

Thanks
_______________________________________________
SPDK mailing list -- spdk(a)lists.01.org
To unsubscribe send an email to spdk-leave(a)lists.01.org

author
#4 lore raw

Thanks Shuuhei and Ben for your response. We will do it as you suggested. I did remember seeing SPDK_THREAD_OP_RESCHED as in the spdk_thread_init method. I guess we will be implementing scale up/down feature slightly later and will look to your reactor code as reference.

Thanks
Hari

#5 lore raw

Hi Hari, Ben, and all,

I implemented dynamic SPDK thread rescheduling onto a sample nvmf application which is not based on event (reactor) framework. I will add a patch to exercise poll group thread migration in this sample application.

https://review.spdk.io/gerrit/c/spdk/spdk/+/2536
https://review.spdk.io/gerrit/c/spdk/spdk/+/2537/1
https://review.spdk.io/gerrit/c/spdk/spdk/+/2538/1
https://review.spdk.io/gerrit/c/spdk/spdk/+/2539/1
https://review.spdk.io/gerrit/c/spdk/spdk/+/2540/1
https://review.spdk.io/gerrit/c/spdk/spdk/+/2541/1
https://review.spdk.io/gerrit/c/spdk/spdk/+/2542/1

Will you review or use them as a reference?

I hope they are sufficiently simple and any help for all as Ben said.

Thanks,
Shuhei

________________________________
差出人: Hari Kadayam <harihara.kadayam(a)gmail.com> 送信日時: 2020年5月19日 6:25
宛先: spdk(a)lists.01.org <spdk(a)lists.01.org> 件名: [SPDK] Re: SPDK Thread and Nvmf QPair migration

Thanks Shuuhei and Ben for your response. We will do it as you suggested. I did remember seeing SPDK_THREAD_OP_RESCHED as in the spdk_thread_init method. I guess we will be implementing scale up/down feature slightly later and will look to your reactor code as reference.

Thanks
Hari
_______________________________________________
SPDK mailing list -- spdk(a)lists.01.org
To unsubscribe send an email to spdk-leave(a)lists.01.org

#6 lore raw

Hi Hari, Ben,

I added a simple patch to exercise repeated poll group migration among multiple POSIX threads.
https://review.spdk.io/gerrit/c/spdk/spdk/+/2556

I hope this will be any help to get better understanding.

Thanks,
Shuhei

________________________________
差出人: 松本周平 / MATSUMOTO,SHUUHEI <shuhei.matsumoto.xt(a)hitachi.com> 送信日時: 2020年5月20日 8:02
宛先: spdk(a)lists.01.org <spdk(a)lists.01.org>
件名: Re: [SPDK] Re: SPDK Thread and Nvmf QPair migration

Hi Hari, Ben, and all,

I implemented dynamic SPDK thread rescheduling onto a sample nvmf application which is not based on event (reactor) framework. I will add a patch to exercise poll group thread migration in this sample application.

https://review.spdk.io/gerrit/c/spdk/spdk/+/2536
https://review.spdk.io/gerrit/c/spdk/spdk/+/2537/1
https://review.spdk.io/gerrit/c/spdk/spdk/+/2538/1
https://review.spdk.io/gerrit/c/spdk/spdk/+/2539/1
https://review.spdk.io/gerrit/c/spdk/spdk/+/2540/1
https://review.spdk.io/gerrit/c/spdk/spdk/+/2541/1
https://review.spdk.io/gerrit/c/spdk/spdk/+/2542/1

Will you review or use them as a reference?

I hope they are sufficiently simple and any help for all as Ben said.

Thanks,
Shuhei

________________________________
差出人: Hari Kadayam <harihara.kadayam(a)gmail.com> 送信日時: 2020年5月19日 6:25
宛先: spdk(a)lists.01.org <spdk(a)lists.01.org> 件名: [SPDK] Re: SPDK Thread and Nvmf QPair migration

Thanks Shuuhei and Ben for your response. We will do it as you suggested. I did remember seeing SPDK_THREAD_OP_RESCHED as in the spdk_thread_init method. I guess we will be implementing scale up/down feature slightly later and will look to your reactor code as reference.

Thanks
Hari
_______________________________________________
SPDK mailing list -- spdk(a)lists.01.org
To unsubscribe send an email to spdk-leave(a)lists.01.org