parameters.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Email: opensource_embedded@phytium.com.cn
  7. *
  8. * Change Logs:
  9. * Date Author Notes
  10. * 2022-10-26 huanghe first commit
  11. *
  12. */
  13. #include "rtconfig.h"
  14. #include <rtthread.h>
  15. #include "fcpu_info.h"
  16. #include "fparameters.h"
  17. /**
  18. * @name: GetCpuMaskToAffval
  19. * @msg: Convert information in cpu_mask to cluster_ID and target_list
  20. * @param {u32} *cpu_mask is each bit of cpu_mask represents a selected CPU, for example, 0x3 represents core0 and CORE1 .
  21. * @param {u32} *cluster_id is information about the cluster in which core resides ,format is
  22. * |--------[bit31-24]-------[bit23-16]-------------[bit15-8]-----------[bit7-0]
  23. * |--------Affinity level3-----Affinity level2-----Affinity level1-----Affinity level0
  24. * @param {u32} *target_list is core mask in cluster
  25. * @return {u32} 0 indicates that the conversion was not successful , 1 indicates that the conversion was successful
  26. */
  27. u32 GetCpuMaskToAffval(u32 *cpu_mask, u32 *cluster_id, u32 *target_list)
  28. {
  29. if (*cpu_mask == 0)
  30. {
  31. return 0;
  32. }
  33. *target_list = 0;
  34. *cluster_id = 0;
  35. if (*cpu_mask & 0x3)
  36. {
  37. if ((*cpu_mask & 0x3) == 0x3)
  38. {
  39. *target_list = 3;
  40. }
  41. else if ((*cpu_mask & 0x1))
  42. {
  43. *target_list = 1;
  44. }
  45. else
  46. {
  47. *target_list = 2;
  48. }
  49. *cpu_mask &= ~0x3;
  50. }
  51. else if (*cpu_mask & 0xc)
  52. {
  53. *cluster_id = 0x100;
  54. if ((*cpu_mask & 0xc) == 0xc)
  55. {
  56. *target_list = 3;
  57. }
  58. else if ((*cpu_mask & 0x4))
  59. {
  60. *target_list = 1;
  61. }
  62. else
  63. {
  64. *target_list = 2;
  65. }
  66. *cpu_mask &= ~0xc;
  67. }
  68. else if (*cpu_mask & 0x30)
  69. {
  70. *cluster_id = 0x200;
  71. if ((*cpu_mask & 0x30) == 0x30)
  72. {
  73. *target_list = 3;
  74. }
  75. else if ((*cpu_mask & 0x10))
  76. {
  77. *target_list = 1;
  78. }
  79. else
  80. {
  81. *target_list = 2;
  82. }
  83. *cpu_mask &= ~0x30;
  84. }
  85. else if (*cpu_mask & 0xc0)
  86. {
  87. *cluster_id = 0x300;
  88. if ((*cpu_mask & 0xc0) == 0xc0)
  89. {
  90. *target_list = 3;
  91. }
  92. else if ((*cpu_mask & 0x40))
  93. {
  94. *target_list = 1;
  95. }
  96. else
  97. {
  98. *target_list = 2;
  99. }
  100. *cpu_mask &= ~0xc0;
  101. }
  102. else
  103. {
  104. *cpu_mask = 0;
  105. return 0;
  106. }
  107. return 1;
  108. }