riscv.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package arch
  15. import (
  16. "yunion.io/x/onecloud/pkg/hostman/guestman/desc"
  17. "yunion.io/x/onecloud/pkg/hostman/options"
  18. )
  19. const (
  20. RISCV_MAX_CPUS = 128
  21. RISCV_SOCKETS = 1
  22. RISCV_THREADS = 1
  23. RISCV_MEM_DEFAULT_SLOTS = 4
  24. )
  25. var RISCV_MAX_MEM_MB uint = 262144
  26. type RISCV struct {
  27. archBase
  28. otherArchBase
  29. }
  30. func (*RISCV) GenerateMachineDesc(accel string) *desc.SGuestMachine {
  31. return &desc.SGuestMachine{
  32. Accel: accel,
  33. }
  34. }
  35. func (*RISCV) GenerateMemDesc() *desc.SGuestMem {
  36. return &desc.SGuestMem{
  37. Slots: RISCV_MEM_DEFAULT_SLOTS,
  38. MaxMem: RISCV_MAX_MEM_MB,
  39. }
  40. }
  41. func (*RISCV) GenerateCpuDesc(cpus uint, cpuMax uint, s KVMGuestInstance) (*desc.SGuestCpu, error) {
  42. var hostCPUPassthrough = options.HostOptions.HostCpuPassthrough
  43. var accel, cpuType string
  44. if s.IsKvmSupport() {
  45. accel = "kvm"
  46. if hostCPUPassthrough {
  47. cpuType = "host"
  48. } else {
  49. // * under KVM, -cpu max is the same as -cpu host
  50. // * under TCG, -cpu max means "emulate with as many features as possible"
  51. cpuType = "max"
  52. }
  53. } else {
  54. accel = "tcg"
  55. cpuType = "max"
  56. }
  57. return &desc.SGuestCpu{
  58. Cpus: cpus,
  59. Sockets: RISCV_SOCKETS,
  60. Cores: cpuMax / RISCV_SOCKETS / RISCV_THREADS,
  61. Threads: RISCV_THREADS,
  62. MaxCpus: cpuMax,
  63. Model: cpuType,
  64. Accel: accel,
  65. }, nil
  66. }