|
11 | 11 | #include <linux/cleanup.h>
|
12 | 12 | #include <linux/cpu.h>
|
13 | 13 | #include <linux/cpufreq.h>
|
| 14 | +#include <linux/cpu_smt.h> |
14 | 15 | #include <linux/device.h>
|
15 | 16 | #include <linux/of.h>
|
16 | 17 | #include <linux/slab.h>
|
@@ -506,6 +507,10 @@ core_initcall(free_raw_capacity);
|
506 | 507 | #endif
|
507 | 508 |
|
508 | 509 | #if defined(CONFIG_ARM64) || defined(CONFIG_RISCV)
|
| 510 | + |
| 511 | +/* Used to enable the SMT control */ |
| 512 | +static unsigned int max_smt_thread_num = 1; |
| 513 | + |
509 | 514 | /*
|
510 | 515 | * This function returns the logic cpu number of the node.
|
511 | 516 | * There are basically three kinds of return values:
|
@@ -565,6 +570,8 @@ static int __init parse_core(struct device_node *core, int package_id,
|
565 | 570 | i++;
|
566 | 571 | } while (1);
|
567 | 572 |
|
| 573 | + max_smt_thread_num = max_t(unsigned int, max_smt_thread_num, i); |
| 574 | + |
568 | 575 | cpu = get_cpu_for_node(core);
|
569 | 576 | if (cpu >= 0) {
|
570 | 577 | if (!leaf) {
|
@@ -677,6 +684,17 @@ static int __init parse_socket(struct device_node *socket)
|
677 | 684 | if (!has_socket)
|
678 | 685 | ret = parse_cluster(socket, 0, -1, 0);
|
679 | 686 |
|
| 687 | + /* |
| 688 | + * Reset the max_smt_thread_num to 1 on failure. Since on failure |
| 689 | + * we need to notify the framework the SMT is not supported, but |
| 690 | + * max_smt_thread_num can be initialized to the SMT thread number |
| 691 | + * of the cores which are successfully parsed. |
| 692 | + */ |
| 693 | + if (ret) |
| 694 | + max_smt_thread_num = 1; |
| 695 | + |
| 696 | + cpu_smt_set_num_threads(max_smt_thread_num, max_smt_thread_num); |
| 697 | + |
680 | 698 | return ret;
|
681 | 699 | }
|
682 | 700 |
|
|
0 commit comments