[RFC/PATCH 1/1] mmc: block: Add MMC write packing statistics

2012-06-06 Thread Maya Erez
The write packing statistics are used for the packed commands unit tests
in order to determine test success or failure

Signed-off-by: Maya Erez me...@codeaurora.org

diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 2785fd4..c33c0c8 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -63,6 +63,11 @@ MODULE_ALIAS(mmc:block);
(rq_data_dir(req) == WRITE))
 #define PACKED_CMD_VER 0x01
 #define PACKED_CMD_WR  0x02
+#define MMC_BLK_UPDATE_STOP_REASON(stats, reason)  \
+   do {\
+   if (stats-enabled) \
+   stats-pack_stop_reason[reason]++;  \
+   } while (0)

 static DEFINE_MUTEX(block_mutex);

@@ -1313,6 +1318,35 @@ static void mmc_blk_rw_rq_prep(struct mmc_queue_req 
*mqrq,
mmc_queue_bounce_pre(mqrq);
 }

+struct mmc_wr_pack_stats *mmc_blk_get_packed_statistics(struct mmc_card *card)
+{
+   if (!card)
+   return NULL;
+
+   return card-wr_pack_stats;
+}
+EXPORT_SYMBOL(mmc_blk_get_packed_statistics);
+
+void mmc_blk_init_packed_statistics(struct mmc_card *card)
+{
+   int max_num_of_packed_reqs = 0;
+
+   if (!card || !card-wr_pack_stats.packing_events)
+   return;
+
+   max_num_of_packed_reqs = card-ext_csd.max_packed_writes;
+
+   spin_lock(card-wr_pack_stats.lock);
+   memset(card-wr_pack_stats.packing_events, 0,
+   (max_num_of_packed_reqs + 1) *
+  sizeof(*card-wr_pack_stats.packing_events));
+   memset(card-wr_pack_stats.pack_stop_reason, 0,
+   sizeof(card-wr_pack_stats.pack_stop_reason));
+   card-wr_pack_stats.enabled = true;
+   spin_unlock(card-wr_pack_stats.lock);
+}
+EXPORT_SYMBOL(mmc_blk_init_packed_statistics);
+
 static u8 mmc_blk_prep_packed_list(struct mmc_queue *mq, struct request *req)
 {
struct request_queue *q = mq-queue;
@@ -1325,6 +1359,7 @@ static u8 mmc_blk_prep_packed_list(struct mmc_queue *mq, 
struct request *req)
u8 put_back = 0;
u8 max_packed_rw = 0;
u8 reqs = 0;
+   struct mmc_wr_pack_stats *stats = card-wr_pack_stats;

mmc_blk_clear_packed(mq-mqrq_cur);

@@ -1359,20 +1394,26 @@ static u8 mmc_blk_prep_packed_list(struct mmc_queue 
*mq, struct request *req)
phys_segments++;
}

+   spin_lock(stats-lock);
+
while (reqs  max_packed_rw - 1) {
spin_lock_irq(q-queue_lock);
next = blk_fetch_request(q);
spin_unlock_irq(q-queue_lock);
-   if (!next)
+   if (!next) {
+   MMC_BLK_UPDATE_STOP_REASON(stats, EMPTY_QUEUE);
break;
+   }

if (next-cmd_flags  REQ_DISCARD ||
next-cmd_flags  REQ_FLUSH) {
+   MMC_BLK_UPDATE_STOP_REASON(stats, FLUSH_OR_DISCARD);
put_back = 1;
break;
}

if (rq_data_dir(cur) != rq_data_dir(next)) {
+   MMC_BLK_UPDATE_STOP_REASON(stats, WRONG_DATA_DIR);
put_back = 1;
break;
}
@@ -1380,18 +1421,22 @@ static u8 mmc_blk_prep_packed_list(struct mmc_queue 
*mq, struct request *req)
if (mmc_req_rel_wr(next) 
(md-flags  MMC_BLK_REL_WR) 
!en_rel_wr) {
+   MMC_BLK_UPDATE_STOP_REASON(stats, REL_WRITE);
put_back = 1;
break;
}

req_sectors += blk_rq_sectors(next);
if (req_sectors  max_blk_count) {
+   if (stats-enabled)
+   stats-pack_stop_reason[EXCEEDS_SECTORS]++;
put_back = 1;
break;
}

phys_segments +=  next-nr_phys_segments;
if (phys_segments  max_phys_segs) {
+   MMC_BLK_UPDATE_STOP_REASON(stats, EXCEEDS_SEGMENTS);
put_back = 1;
break;
}
@@ -1407,6 +1452,15 @@ static u8 mmc_blk_prep_packed_list(struct mmc_queue *mq, 
struct request *req)
spin_unlock_irq(q-queue_lock);
}

+   if (stats-enabled) {
+   if (reqs + 1 = card-ext_csd.max_packed_writes)
+   stats-packing_events[reqs + 1]++;
+   if (reqs + 1 == max_packed_rw)
+   MMC_BLK_UPDATE_STOP_REASON(stats, THRESHOLD);
+   }
+
+   spin_unlock(stats-lock);
+
if (reqs  0) {
list_add(req-queuelist, mq-mqrq_cur-packed_list);
mq-mqrq_cur-packed_num = ++reqs;
diff --git a/drivers/mmc/core/bus.c 

Re: [RFC/PATCH 1/1] mmc: block: Add MMC write packing statistics

2012-06-06 Thread Rahul Bedarkar
See comments inline.

On Wed, Jun 6, 2012 at 11:46 AM, Maya Erez me...@codeaurora.org wrote:
 The write packing statistics are used for the packed commands unit tests
 in order to determine test success or failure

 Signed-off-by: Maya Erez me...@codeaurora.org

 diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
 index 2785fd4..c33c0c8 100644
 --- a/drivers/mmc/card/block.c
 +++ b/drivers/mmc/card/block.c
 @@ -63,6 +63,11 @@ MODULE_ALIAS(mmc:block);
                        (rq_data_dir(req) == WRITE))
  #define PACKED_CMD_VER         0x01
  #define PACKED_CMD_WR          0x02
 +#define MMC_BLK_UPDATE_STOP_REASON(stats, reason)                      \
 +       do {                                                            \
 +               if (stats-enabled)                                     \
 +                       stats-pack_stop_reason[reason]++;              \
 +       } while (0)

  static DEFINE_MUTEX(block_mutex);

 @@ -1313,6 +1318,35 @@ static void mmc_blk_rw_rq_prep(struct mmc_queue_req 
 *mqrq,
        mmc_queue_bounce_pre(mqrq);
  }

 +struct mmc_wr_pack_stats *mmc_blk_get_packed_statistics(struct mmc_card 
 *card)
 +{
 +       if (!card)
 +               return NULL;
 +
 +       return card-wr_pack_stats;
 +}
 +EXPORT_SYMBOL(mmc_blk_get_packed_statistics);
 +
 +void mmc_blk_init_packed_statistics(struct mmc_card *card)
 +{
 +       int max_num_of_packed_reqs = 0;
 +
 +       if (!card || !card-wr_pack_stats.packing_events)
 +               return;
 +
 +       max_num_of_packed_reqs = card-ext_csd.max_packed_writes;
 +
 +       spin_lock(card-wr_pack_stats.lock);
 +       memset(card-wr_pack_stats.packing_events, 0,
 +               (max_num_of_packed_reqs + 1) *
 +              sizeof(*card-wr_pack_stats.packing_events));
 +       memset(card-wr_pack_stats.pack_stop_reason, 0,
 +               sizeof(card-wr_pack_stats.pack_stop_reason));
 +       card-wr_pack_stats.enabled = true;
 +       spin_unlock(card-wr_pack_stats.lock);
 +}
 +EXPORT_SYMBOL(mmc_blk_init_packed_statistics);
 +
  static u8 mmc_blk_prep_packed_list(struct mmc_queue *mq, struct request *req)
  {
        struct request_queue *q = mq-queue;
 @@ -1325,6 +1359,7 @@ static u8 mmc_blk_prep_packed_list(struct mmc_queue 
 *mq, struct request *req)
        u8 put_back = 0;
        u8 max_packed_rw = 0;
        u8 reqs = 0;
 +       struct mmc_wr_pack_stats *stats = card-wr_pack_stats;

        mmc_blk_clear_packed(mq-mqrq_cur);

 @@ -1359,20 +1394,26 @@ static u8 mmc_blk_prep_packed_list(struct mmc_queue 
 *mq, struct request *req)
                phys_segments++;
        }

 +       spin_lock(stats-lock);
 +
        while (reqs  max_packed_rw - 1) {
                spin_lock_irq(q-queue_lock);
                next = blk_fetch_request(q);
                spin_unlock_irq(q-queue_lock);
 -               if (!next)
 +               if (!next) {
 +                       MMC_BLK_UPDATE_STOP_REASON(stats, EMPTY_QUEUE);
                        break;
 +               }

                if (next-cmd_flags  REQ_DISCARD ||
                                next-cmd_flags  REQ_FLUSH) {
 +                       MMC_BLK_UPDATE_STOP_REASON(stats, FLUSH_OR_DISCARD);
                        put_back = 1;
                        break;
                }

                if (rq_data_dir(cur) != rq_data_dir(next)) {
 +                       MMC_BLK_UPDATE_STOP_REASON(stats, WRONG_DATA_DIR);
                        put_back = 1;
                        break;
                }
 @@ -1380,18 +1421,22 @@ static u8 mmc_blk_prep_packed_list(struct mmc_queue 
 *mq, struct request *req)
                if (mmc_req_rel_wr(next) 
                                (md-flags  MMC_BLK_REL_WR) 
                                !en_rel_wr) {
 +                       MMC_BLK_UPDATE_STOP_REASON(stats, REL_WRITE);
                        put_back = 1;
                        break;
                }

                req_sectors += blk_rq_sectors(next);
                if (req_sectors  max_blk_count) {
 +                       if (stats-enabled)
 +                               stats-pack_stop_reason[EXCEEDS_SECTORS]++;
                        put_back = 1;
                        break;
                }

                phys_segments +=  next-nr_phys_segments;
                if (phys_segments  max_phys_segs) {
 +                       MMC_BLK_UPDATE_STOP_REASON(stats, EXCEEDS_SEGMENTS);
                        put_back = 1;
                        break;
                }
 @@ -1407,6 +1452,15 @@ static u8 mmc_blk_prep_packed_list(struct mmc_queue 
 *mq, struct request *req)
                spin_unlock_irq(q-queue_lock);
        }

 +       if (stats-enabled) {
 +               if (reqs + 1 = card-ext_csd.max_packed_writes)
 +                       stats-packing_events[reqs + 1]++;
 +               if (reqs + 1 == max_packed_rw)
 +                       MMC_BLK_UPDATE_STOP_REASON(stats, THRESHOLD);
 +       }
 +
 +       spin_unlock(stats-lock);
 +
     

Re: [RFC/PATCH 1/1] mmc: block: Add MMC write packing statistics

2012-06-06 Thread David Brown
On Wed, Jun 06, 2012 at 12:02:10PM +0530, Rahul Bedarkar wrote:

  +static ssize_t mmc_wr_pack_stats_read(struct file *filp, char __user *ubuf,
  +                               size_t cnt, loff_t *ppos)
  +{
  +       struct mmc_card *card = filp-private_data;
  +       struct mmc_wr_pack_stats *pack_stats;
  +       int i;

 Best practice is to initialize variables at the time of declaration,
 even if you initialize it before using. Many times we forget to do
 that and there could be logical errors.

gcc will often emit a warning if a variable is used before
initialization.  There seems to be a trend amongst kernel developers
to eschew redundant initializations, since they do actually generate
code.  In fact, there is a macro 'uninitialized_var(x)' to suppress
the warning from the compiler when it is incorrect, so that a variable
doesn't have to be initialized when not really needed.

Outside of the kernel, though, I would otherwise agree with you.

David

-- 
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
--
To unsubscribe from this list: send the line unsubscribe linux-mmc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC/PATCH 1/1] mmc: block: Add MMC write packing statistics

2012-06-06 Thread merez
 +
 +       for (i = 1 ; i = max_num_of_packed_reqs ; ++i) {
 This is something magical number for iterations. why can not we start
from
 zero.
The statistics are kept in the array in the index that equals the number
of packed requests. Therefore, they are kept in the array in indexes 1 to
max num of packed reqs.
I will add a comment to explain that.

Thanks,
Maya Erez
Consultant for Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum






--
To unsubscribe from this list: send the line unsubscribe linux-mmc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html