Commit 1c270b7
committed
workqueue: Move nr_active handling into helpers
__queue_work(), pwq_dec_nr_in_flight() and wq_adjust_max_active() were
open-coding nr_active handling, which is fine given that the operations are
trivial. However, the planned unbound nr_active update will make them more
complicated, so let's move them into helpers.
- pwq_tryinc_nr_active() is added. It increments nr_active if under
max_active limit and return a boolean indicating whether inc was
successful. Note that the function is structured to accommodate future
changes. __queue_work() is updated to use the new helper.
- pwq_activate_first_inactive() is updated to use pwq_tryinc_nr_active() and
thus no longer assumes that nr_active is under max_active and returns a
boolean to indicate whether a work item has been activated.
- wq_adjust_max_active() no longer tests directly whether a work item can be
activated. Instead, it's updated to use the return value of
pwq_activate_first_inactive() to tell whether a work item has been
activated.
- nr_active decrement and activating the first inactive work item is
factored into pwq_dec_nr_active().
v3: - WARN_ON_ONCE(!WORK_STRUCT_INACTIVE) added to __pwq_activate_work() as
now we're calling the function unconditionally from
pwq_activate_first_inactive().
v2: - wq->max_active now uses WRITE/READ_ONCE() as suggested by Lai.
Signed-off-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Lai Jiangshan <jiangshanlai@gmail.com>1 parent 4c63803 commit 1c270b7
1 file changed
Lines changed: 67 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1468 | 1468 | | |
1469 | 1469 | | |
1470 | 1470 | | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
1471 | 1474 | | |
1472 | 1475 | | |
1473 | 1476 | | |
1474 | 1477 | | |
1475 | | - | |
| 1478 | + | |
1476 | 1479 | | |
1477 | 1480 | | |
1478 | 1481 | | |
| |||
1497 | 1500 | | |
1498 | 1501 | | |
1499 | 1502 | | |
1500 | | - | |
| 1503 | + | |
| 1504 | + | |
| 1505 | + | |
| 1506 | + | |
| 1507 | + | |
| 1508 | + | |
| 1509 | + | |
| 1510 | + | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + | |
| 1517 | + | |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
| 1522 | + | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
| 1531 | + | |
| 1532 | + | |
| 1533 | + | |
| 1534 | + | |
| 1535 | + | |
| 1536 | + | |
| 1537 | + | |
| 1538 | + | |
| 1539 | + | |
| 1540 | + | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + | |
| 1548 | + | |
| 1549 | + | |
| 1550 | + | |
| 1551 | + | |
| 1552 | + | |
| 1553 | + | |
| 1554 | + | |
| 1555 | + | |
1501 | 1556 | | |
1502 | | - | |
1503 | | - | |
| 1557 | + | |
1504 | 1558 | | |
1505 | | - | |
| 1559 | + | |
| 1560 | + | |
| 1561 | + | |
| 1562 | + | |
1506 | 1563 | | |
1507 | 1564 | | |
1508 | 1565 | | |
| |||
1520 | 1577 | | |
1521 | 1578 | | |
1522 | 1579 | | |
1523 | | - | |
1524 | | - | |
1525 | | - | |
1526 | | - | |
1527 | | - | |
1528 | | - | |
1529 | | - | |
1530 | | - | |
| 1580 | + | |
| 1581 | + | |
1531 | 1582 | | |
1532 | 1583 | | |
1533 | 1584 | | |
| |||
1829 | 1880 | | |
1830 | 1881 | | |
1831 | 1882 | | |
1832 | | - | |
1833 | | - | |
| 1883 | + | |
1834 | 1884 | | |
1835 | 1885 | | |
1836 | 1886 | | |
1837 | 1887 | | |
1838 | | - | |
1839 | 1888 | | |
1840 | 1889 | | |
1841 | 1890 | | |
| |||
4687 | 4736 | | |
4688 | 4737 | | |
4689 | 4738 | | |
4690 | | - | |
4691 | | - | |
4692 | | - | |
| 4739 | + | |
| 4740 | + | |
4693 | 4741 | | |
4694 | 4742 | | |
4695 | 4743 | | |
| |||
0 commit comments