[rtems-libbsd commit] mmc: Optimize mmc_wait_for_req()

Sebastian Huber sebh at rtems.org
Fri Apr 27 11:30:36 UTC 2018


Module:    rtems-libbsd
Branch:    master
Commit:    c7e162abd85cd8247894d84b3352189c6d4cd43c
Changeset: http://git.rtems.org/rtems-libbsd/commit/?id=c7e162abd85cd8247894d84b3352189c6d4cd43c

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Thu Apr 26 15:19:42 2018 +0200

mmc: Optimize mmc_wait_for_req()

Use a self-contained RTEMS binary semaphore instead of msleep() and
wakeup().  This is itself more efficient and in addition allows the use
of mmc_wakeup() in interrupt context.

---

 freebsd/sys/dev/mmc/mmc.c    | 12 ++++++++++++
 freebsd/sys/dev/mmc/mmcreg.h |  7 +++++++
 2 files changed, 19 insertions(+)

diff --git a/freebsd/sys/dev/mmc/mmc.c b/freebsd/sys/dev/mmc/mmc.c
index c19fae7..023091e 100644
--- a/freebsd/sys/dev/mmc/mmc.c
+++ b/freebsd/sys/dev/mmc/mmc.c
@@ -394,6 +394,7 @@ mmc_highest_voltage(uint32_t ocr)
 static void
 mmc_wakeup(struct mmc_request *req)
 {
+#ifndef __rtems__
 	struct mmc_softc *sc;
 
 	sc = (struct mmc_softc *)req->done_data;
@@ -401,12 +402,18 @@ mmc_wakeup(struct mmc_request *req)
 	req->flags |= MMC_REQ_DONE;
 	MMC_UNLOCK(sc);
 	wakeup(req);
+#else /* __rtems__ */
+	rtems_binary_semaphore_post(&req->req_done);
+#endif /* __rtems__ */
 }
 
 static int
 mmc_wait_for_req(struct mmc_softc *sc, struct mmc_request *req)
 {
 
+#ifdef __rtems__
+	rtems_binary_semaphore_init(&req->req_done, "mmc_req_done");
+#endif /* __rtems__ */
 	req->done = mmc_wakeup;
 	req->done_data = sc;
 	if (mmc_debug > 1) {
@@ -418,10 +425,15 @@ mmc_wait_for_req(struct mmc_softc *sc, struct mmc_request *req)
 			printf("\n");
 	}
 	MMCBR_REQUEST(device_get_parent(sc->dev), sc->dev, req);
+#ifndef __rtems__
 	MMC_LOCK(sc);
 	while ((req->flags & MMC_REQ_DONE) == 0)
 		msleep(req, &sc->sc_mtx, 0, "mmcreq", 0);
 	MMC_UNLOCK(sc);
+#else /* __rtems__ */
+	rtems_binary_semaphore_wait(&req->req_done);
+	rtems_binary_semaphore_destroy(&req->req_done);
+#endif /* __rtems__ */
 	if (mmc_debug > 2 || (mmc_debug > 0 && req->cmd->error != MMC_ERR_NONE))
 		device_printf(sc->dev, "CMD%d RESULT: %d\n",
 		    req->cmd->opcode, req->cmd->error);
diff --git a/freebsd/sys/dev/mmc/mmcreg.h b/freebsd/sys/dev/mmc/mmcreg.h
index 359f31d..39680ad 100644
--- a/freebsd/sys/dev/mmc/mmcreg.h
+++ b/freebsd/sys/dev/mmc/mmcreg.h
@@ -54,6 +54,9 @@
 
 #ifndef DEV_MMC_MMCREG_H
 #define	DEV_MMC_MMCREG_H
+#ifdef __rtems__
+#include <rtems/thread.h>
+#endif /* __rtems__ */
 
 /*
  * This file contains the register definitions for the mmc and sd buses.
@@ -173,8 +176,12 @@ struct mmc_request {
 	struct mmc_command *stop;
 	void (*done)(struct mmc_request *); /* Completion function */
 	void *done_data;		/* requestor set data */
+#ifndef __rtems__
 	uint32_t flags;
 #define	MMC_REQ_DONE	1
+#else /* __rtems__ */
+	rtems_binary_semaphore req_done;
+#endif /* __rtems__ */
 };
 
 /* Command definitions */




More information about the vc mailing list