Hi.
I have the following scenario. DeviceIOControl calls are received (from a
queue with parallel dispatch). The work to be done can block so I am
creating a workitem and then returning from EvtIoDeviceControl(). The
workitem does the work and completes the request. If a second IO control is
recieved whilst the first workitem is still busy, i create a new workitem
etc..

Question 1: Is it ok to dynamically create multiple workitems? Is there a
way of destroying them after use? Or would it be better to just create a
number of them in EvtDeviceAdd and then just keep track of the ones in use?

The workitem is created as follows:
WDF_OBJECT_ATTRIBUTES_INIT( &IOCTLWorkItemAttributes );
WDF_OBJECT_ATTRIBUTES_SET_CONTEXT_TYPE( &IOCTLWorkItemAttributes,
IOCTL_WORKITEM_EXTENSION );
IOCTLWorkItemAttributes.ParentObject = device;
WDF_WORKITEM_CONFIG_INIT( &IOCTLWorkitemConfig, PCIMotionEvtIOCTLWorkItem );
IOCTLWorkitemConfig.AutomaticSerialization = FALSE;
status = WdfWorkItemCreate( &IOCTLWorkitemConfig, &IOCTLWorkItemAttributes,
&hIOCTLWorkItem);

Question 2: Does each workitem created get a unique context space, or do
they all share the same context?

Thanks in advance.
Laurence

Re: WorkItem in KMDF 1.0 by Eliyas

Eliyas
Fri May 19 11:18:40 CDT 2006

>
> Question 1: Is it ok to dynamically create multiple workitems?

Not a good idea. If you get larger number of I/Os simulateneously, you will
run into performance problems.

> Is there a way of destroying them after use?

You can destroy the workitem from within the workitem callback by calling
WdfObjectDelete.

>Or would it be better to just create a number of them in EvtDeviceAdd and
>then just keep track of the ones in use?
>

How many would you create? Do you know upfront how many I/Os you are going
to get simultaneously. You can solve this problem by using a single
workitem. I'm thinking of an easy way to solve this problem using a manual
queue. I will draft a logic and post it here.

Can you describe more about your driver? Does it receive read & write
requests? How are they processed? Does it receive other type of ioctl
requests?


>
> Question 2: Does each workitem created get a unique context space, or do
> they all share the same context?
>

Each workitem will have its own private context.


-Eliyas




Re: WorkItem in KMDF 1.0 by Maxim

Maxim
Fri May 19 11:28:13 CDT 2006

> Question 1: Is it ok to dynamically create multiple workitems?

Yes.

>Is there a way of destroying them after use?

In usual Windows, you can free the memory containing the work item from the
item itself. Dunno on KMDF.

> Question 2: Does each workitem created get a unique context space, or do
> they all share the same context?

In WDM - yes, you provide the context pointer yourself. Dunno on KMDF.

--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
maxim@storagecraft.com
http://www.storagecraft.com