Re: USB power accounting at root hub level

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

Thanks again for the quick feedback.

Le Mon, 25 Jul 2011 15:08:53 -0400 (EDT),
Alan Stern <stern@xxxxxxxxxxxxxxxxxxx> a écrit :

> > I would have expected udev->bus_mA to be 75 mA for the second device,
> > so that the 100 mA configuration gets rejected.
> 
> No.  The USB stack doesn't enforce any scheme for dividing up power 
> among a hub's children.  All it does is log a warning if the devices 
> want more power than the total available.

Ok. This is also what I understood.

> > However, looking at
> > http://lxr.free-electrons.com/source/drivers/usb/core/hub.c#L1147, it
> > appears that the hub->mA_per_port field is defined to hdev->bus_mA
> > (i.e, the power budget). So it means that when we define a power budget
> > of 175 mA, the USB core understands that it is 175 mA per port that is
> > available, and not 175 mA globally for all ports of the root hub. I
> > suspect this explains the behavior I'm seeing.
> > 
> > Unfortunately, this contradicts the computation done in
> > hub_power_remaining() at
> > http://lxr.free-electrons.com/source/drivers/usb/core/hub.c#L3014,
> > which rightfully concludes that 25mA is missing. And this also seems to
> > make it difficult to define a global root hub power limit.
> 
> There's no contradiction.  If 175 mA total are available, then one way
> to apportion it is to plug in a single device requiring 175 mA.  In
> other words, there really is up to 175 mA available for each port.

Hum, I'm sorry, but I still see a contradiction :

 * On one side, there is a computation that assumes that hdev->bus_mA
   is a *per-port* current limit (and this computation is used to
   reject new USB configurations from connecting) ;

 * On another side, there is a computation that assumes that
   hdev->bus_mA is a *global hub* current limit (and this computation
   is used to print a warning in the kernel messages).

If I set a global current limit of 175 mA, then two devices of 100 mA
shouldn't be allowed to connect.

> > Isn't there a contradiction here ? Shouldn't the hdev->bus_mA be
> > understood as a global hub power budget, and not a per-port power
> > budget ?
> 
> That _is_ how it is interpreted.

Well, I don't think so, since by the example above, we have seen that
two 100 mA devices (which accounts for 200 mA of power) can connect to
a hub limited to 175 mA.

> It looks like your real problem is in hcd.c line 2467 (in 
> usb_add_hcd()):
> 
> 	rhdev->bus_mA = min(500u, hcd->power_budget);
> 
> We probably shouldn't use the min() operation here, just set
> rhdev->bus_mA to hcd->power_budget.  However, I'm not sure how the
> various host controller drivers set the power_budget field; some of
> them may set it to the total power divided by the number of ports
> rather than the total power.  If they do, they will have to be fixed
> when this change is made.

This precise instruction is a fairly clear indication that the
rhdev->bus_mA value is a per-port limit and not a global hub limit.
Otherwise, there wouldn't have been this maximum value of 500mA.

Am I missing something ?

Thomas
-- 
Thomas Petazzoni, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux