691-net-add-sysfs-attribute-for-enabling-threaded-NAPI.patch 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. From: Felix Fietkau <[email protected]>
  2. Date: Fri, 21 Aug 2020 15:07:54 +0200
  3. Subject: [PATCH] net: add sysfs attribute for enabling threaded NAPI
  4. This can be used to enable threaded NAPI on drivers that did not explicitly
  5. request it.
  6. Suggested-by: Eric Dumazet <[email protected]>
  7. Signed-off-by: Felix Fietkau <[email protected]>
  8. ---
  9. --- a/net/core/net-sysfs.c
  10. +++ b/net/core/net-sysfs.c
  11. @@ -472,6 +472,52 @@ static ssize_t proto_down_store(struct d
  12. }
  13. NETDEVICE_SHOW_RW(proto_down, fmt_dec);
  14. +static int change_napi_threaded(struct net_device *dev, unsigned long val)
  15. +{
  16. + struct napi_struct *napi;
  17. +
  18. + if (list_empty(&dev->napi_list))
  19. + return -EOPNOTSUPP;
  20. +
  21. + list_for_each_entry(napi, &dev->napi_list, dev_list) {
  22. + if (val)
  23. + set_bit(NAPI_STATE_THREADED, &napi->state);
  24. + else
  25. + clear_bit(NAPI_STATE_THREADED, &napi->state);
  26. + }
  27. +
  28. + return 0;
  29. +}
  30. +
  31. +static ssize_t napi_threaded_store(struct device *dev,
  32. + struct device_attribute *attr,
  33. + const char *buf, size_t len)
  34. +{
  35. + return netdev_store(dev, attr, buf, len, change_napi_threaded);
  36. +}
  37. +
  38. +static ssize_t napi_threaded_show(struct device *dev,
  39. + struct device_attribute *attr,
  40. + char *buf)
  41. +{
  42. + struct net_device *netdev = to_net_dev(dev);
  43. + struct napi_struct *napi;
  44. + bool enabled = false;
  45. +
  46. + if (!rtnl_trylock())
  47. + return restart_syscall();
  48. +
  49. + list_for_each_entry(napi, &netdev->napi_list, dev_list) {
  50. + if (test_bit(NAPI_STATE_THREADED, &napi->state))
  51. + enabled = true;
  52. + }
  53. +
  54. + rtnl_unlock();
  55. +
  56. + return sprintf(buf, fmt_dec, enabled);
  57. +}
  58. +static DEVICE_ATTR_RW(napi_threaded);
  59. +
  60. static ssize_t phys_port_id_show(struct device *dev,
  61. struct device_attribute *attr, char *buf)
  62. {
  63. @@ -564,6 +610,7 @@ static struct attribute *net_class_attrs
  64. &dev_attr_tx_queue_len.attr,
  65. &dev_attr_gro_flush_timeout.attr,
  66. &dev_attr_napi_defer_hard_irqs.attr,
  67. + &dev_attr_napi_threaded.attr,
  68. &dev_attr_phys_port_id.attr,
  69. &dev_attr_phys_port_name.attr,
  70. &dev_attr_phys_switch_id.attr,