Skip to contentSkip to conversation

MD Acceleration: Base ADMA interface

RFC PATCH In review Dan Williams 3 participants 5 messages Feb 3, 2006 – Feb 4, 2006 MD RAID

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 MD Acceleration: Base ADMA interface

This is a draft implementation of the ADMA interface. The basic premise is an interface that receives descriptors from a client and processes them in a separate thread. The descriptors address a wide range of commands (xor, copy, compare, etc).

On the front end a client can assume that operations queued to an engine will be executed in queued order. On the backend it is expected that multiple hardware DMA channels may comprise a single ADMA engine. For example an XOR channel and a normal memory copy channel could be presented to a client as a single ADMA engine.

The descriptor should remain under complete control of the engine. This allows the backend engine code to format the descriptor according to any hardware requirements/constraints. For this reason all access to descriptor variables from the client side is through accessor routines. Later on theses routines will take into account engine specific descriptor constraints.

For now this code makes some pio_adma_engine assumptions which will be addressed in future releases.

drivers/adma/Kconfig new file +16 -0
new file mode 100644
index 0000000..772bd44
@@ -0,0 +1,16 @@
+menu "Asynchronous memory engine support (ADMA)"
+
+config ADMA
+	bool "Support asynchronous memory engines"
+	help
+	  Support asynchronous (hardware acceleratated) dma, xor, memset, etc... 
+	  Required for RAID 5/6.
+
+config PIO_ADMA
+	bool "Software ADMA engine implementation"
+	depends on ADMA
+	help
+	  Select this option to use a soft engine rather than a hardware accelerated
+	  ADMA engine
+
+endmenu
drivers/adma/Makefile new file +2 -0
new file mode 100644
index 0000000..2d1d640
@@ -0,0 +1,2 @@
+obj-$(CONFIG_ADMA)		+= adma.o
+obj-$(CONFIG_PIO_ADMA)		+= pio_adma.o
drivers/adma/adma.c new file +255 -0

255 lines not on this page · raw message

drivers/adma/pio_adma.c new file +91 -0

91 lines not on this page · raw message

include/linux/adma/adma.h new file +132 -0

132 lines not on this page · raw message

#1 lore raw

Hello, Dan.

Quoted 18 lines · Dan Williams

This is a draft implementation of the ADMA interface. The basic premise is an interface that receives descriptors from a client and processes them in a separate thread. The descriptors address a wide range of commands (xor, copy, compare, etc).

On the front end a client can assume that operations queued to an engine will be executed in queued order. On the backend it is expected that multiple hardware DMA channels may comprise a single ADMA engine. For example an XOR channel and a normal memory copy channel could be presented to a client as a single ADMA engine.

The descriptor should remain under complete control of the engine. This allows the backend engine code to format the descriptor according to any hardware requirements/constraints. For this reason all access to descriptor variables from the client side is through accessor routines. Later on theses routines will take into account engine specific descriptor constraints.

Quoted 4 lines

For now this code makes some pio_adma_engine assumptions which will be addressed in future releases.

I have some comments about asynchronous usage of adma_queue_desc(), adma_run(eng) and adma_spin_wait().

Existense of adma_spin_wait() is a sign of tricky bugs in near future, since it hurts performance by busy loop and creates possibility to catch a race, if busy flag will be set/cleared in the way adma_spin_wait() will not see it.

I would recommend to modify state machine in async md_raid and eliminate adma_spin_wait() completely.

In acrypto crypto provider can specially mark crypto_session (descriptor in your case) so when provider calls queueing mechanism (adma_queue_desc() in your case) session is not queued but processed immediately(adma_run()), so there is no need in busy waiting.

Btw, as optimisation step, it is very usefull sometimes (if queueing context allows to sleep) to call needed callbacks directly and do not postpone work to be done by thread.

Signature · 1 line
	Evgeniy Polyakov
#2 lore raw

Hi Evengiy,

Quoted 11 lines · Evgeniy Polyakov

I have some comments about asynchronous usage of adma_queue_desc(), adma_run(eng) and adma_spin_wait().

Existense of adma_spin_wait() is a sign of tricky bugs in near future, since it hurts performance by busy loop and creates possibility to catch a race, if busy flag will be set/cleared in the way adma_spin_wait() will not see it.

I would recommend to modify state machine in async md_raid and eliminate adma_spin_wait() completely.

Quoted 7 lines

In acrypto crypto provider can specially mark crypto_session (descriptor in your case) so when provider calls queueing mechanism (adma_queue_desc() in your case) session is not queued but processed immediately(adma_run()), so there is no need in busy waiting.

Btw, as optimisation step, it is very usefull sometimes (if queueing context allows to sleep) to call needed callbacks directly and do not postpone work to be done by thread.

Thanks for the feedback, I will implement these changes. Also, now that you have given me some hints as to the acrypto vocabulary, I can start looking into integration and cross pollenation efforts.

Dan

#3 lore raw

Hello, Dan.

Quoted 4 lines · Dan Williams

Thanks for the feedback, I will implement these changes. Also, now that you have given me some hints as to the acrypto vocabulary, I can start looking into integration and cross pollenation efforts.

You can find more documentation about acrypto design and implementation on project's page:

http://tservice.net.ru/~s0mbre/old/index.php?section=projects&item=acrypto

Quoted 1 line

Dan

Signature · 1 line
	Evgeniy Polyakov
#4 lore raw
In reply to Dan Williams

Trivial locking comment.
Selected functions below (adma_queue_desc() and adma_run()) protects list of descriptor manipulations by only simple lock.
If it is possible to queue descriptors from interrupt/bh context, locking should be changed.

drivers/adma/adma.c line 56

Quoted 8 lines · Dan Williams
drivers/adma/adma.c new file +8 -0
+/* add descriptor to the process list and conditionally initiate operations */
+void adma_queue_desc(adma_desc_t *desc, int wake)
+{
+	adma_engine_t *eng = desc->engine;
+
+	spin_lock(&eng->lock);
+	list_add_tail(&desc->chain, &eng->desc_chain);
+	atomic_inc(&eng->ops_pending);

This counter is never used actually...

Quoted 6 lines
drivers/adma/adma.c new file +6 -0
+	spin_unlock(&eng->lock);
+
+	if (wake) adma_wakeup_thread(eng->thread);
+
+	dump_desc(desc);
+}

...

Quoted 22 lines
drivers/adma/adma.c new file +22 -0
+
+/*
+ * This thread churns through the descriptor chain
+ * Runs the command and if necessary calls the callback function.
+ * Note: This thread makes pio_adma_engine assumptions for now
+ */
+void adma_run(adma_engine_t *eng)
+{
+	adma_desc_t *desc, *prev_desc;
+	int op = 0;
+
+	while(1) {
+		struct list_head *first;
+
+		spin_lock(&eng->lock);
+		if (list_empty(&eng->desc_chain))
+			break;
+
+		first = eng->desc_chain.next;
+
+		/* will be used to satisfy ordering requirements for adma
+		 * engines that process copy and xor operatations on different

drivers/adma/adma.c line 100

Quoted 10 lines
drivers/adma/adma.c new file +10 -0
+		 * channels 
+		 */ 
+		prev_desc = op++ ? desc : NULL;
+		desc = list_entry(first, adma_desc_t, chain);
+		dump_desc(desc);
+
+		list_del_init(first);
+
+		atomic_dec(&eng->ops_pending);
+		spin_unlock(&eng->lock);

If ops_pending could be used as engine's reference counter, it should not be dropped here, but it looks like it is unused.

Quoted 73 lines
drivers/adma/adma.c new file +73 -0
+		switch(desc->command) {
+			case ADMA_COPY:
+				eng->cpy_op(desc->buf[0], desc->buf[1], desc->len);
+				break;
+			case ADMA_SET:
+				eng->set_block_op(desc->sources, desc->len, desc->buf, desc->pattern);
+				break;
+			case ADMA_COMPARE:
+				if (eng->cmp_op(desc->buf[0], 
+				    desc->buf[1], 
+				    desc->len))
+					set_bit(ADMA_STAT_CMP, &desc->flags);
+				else
+					clear_bit(ADMA_STAT_CMP, &desc->flags);
+				break;
+			case ADMA_XOR:
+				eng->xor_block_op(desc->sources, desc->len, desc->buf);
+				break;
+			case ADMA_PQXOR:
+				printk("%s: Error ADMA_PQXOR not yet implemented\n", __FUNCTION__);
+				BUG();
+				break;
+		}
+		adma_check_status(desc);
+
+		if(desc->callback)
+			desc->callback(desc, desc->args);
+		else if(test_bit(ADMA_AUTO_REAP, &desc->flags)) {
+			BUG_ON(desc->args != NULL);
+			adma_put_desc(desc);
+		}
+	}
+	spin_unlock(&eng->lock);
+}
+
+static int adma_thread(void * arg)
+{
+	adma_thread_t *thread = arg;
+
+	/*
+	 * This thread handles:
+	 *	> issuing descriptors to an adma engine
+	 *	> maintaining order between dependent operations
+	 *	> garbage collecting descriptor resources (upon request)
+	 *	> running the pio version of an operation when underlying
+	 *	  hardware support is not present
+	 */
+
+	allow_signal(SIGKILL);
+	while (!kthread_should_stop()) {
+
+		/* We need to wait INTERRUPTIBLE so that
+		 * we don't add to the load-average.
+		 * That means we need to be sure no signals are
+		 * pending
+		 */
+		if (signal_pending(current))
+			flush_signals(current);
+
+		wait_event_interruptible_timeout
+			(thread->wqueue,
+			 test_bit(THREAD_WAKEUP, &thread->flags)
+			 || kthread_should_stop(),
+			 thread->timeout);
+		try_to_freeze();
+
+		clear_bit(THREAD_WAKEUP, &thread->flags);
+
+		thread->run(thread->eng);
+	}
+
+	return 0;
+}
Signature · 1 line
	Evgeniy Polyakov