Skip to content

Commit

Permalink
dmaengine: of_dma: approximate an average distribution
Browse files Browse the repository at this point in the history
Currently the following DT description would result in dmac0 always
being tried first and dmac1 second if dmac0 was unavailable. This
results in heavier use of dmac0 then of dmac1. This patch adds an
approximate average distribution over the two nodes lessening the load
of anyone of them.

   i2c6: i2c@e60b0000 {
           ...
           dmas = <&dmac0 0x77>, <&dmac0 0x78>,
                  <&dmac1 0x77>, <&dmac1 0x78>;
           dma-names = "tx", "rx", "tx", "rx";
           ...
   };

Signed-off-by: Arnd Bergmann <[email protected]>
Signed-off-by: Niklas Söderlund <[email protected]>
Suggested-by: Arnd Bergmann <[email protected]>
Signed-off-by: Vinod Koul <[email protected]>
  • Loading branch information
Niklas Söderlund authored and Vinod Koul committed May 14, 2016
1 parent d57d3a4 commit 20ea6be
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions drivers/dma/of-dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,9 @@ struct dma_chan *of_dma_request_slave_channel(struct device_node *np,
struct of_phandle_args dma_spec;
struct of_dma *ofdma;
struct dma_chan *chan;
int count, i;
int count, i, start;
int ret_no_channel = -ENODEV;
static atomic_t last_index;

if (!np || !name) {
pr_err("%s: not enough information provided\n", __func__);
Expand All @@ -259,8 +260,15 @@ struct dma_chan *of_dma_request_slave_channel(struct device_node *np,
return ERR_PTR(-ENODEV);
}

/*
* approximate an average distribution across multiple
* entries with the same name
*/
start = atomic_inc_return(&last_index);
for (i = 0; i < count; i++) {
if (of_dma_match_channel(np, name, i, &dma_spec))
if (of_dma_match_channel(np, name,
(i + start) % count,
&dma_spec))
continue;

mutex_lock(&of_dma_lock);
Expand Down

0 comments on commit 20ea6be

Please sign in to comment.