設定自動調度管理工具

Orchestrator 是在本機 SDV 代理程式,在每個虛擬機器 (VM) 上執行,並提供機制來控制何時應建立、啟動、停止或刪除服務套件。這項作業是透過自動化調度管理設定完成,您可以在設定中定義一組規則,決定何時及如何對服務套件執行個體執行動作。這些規則是根據車輛、電源和自訂模式而定。

您可以在設定 APEX 中,或透過個別 VM 設定來設定 Orchestrator。這個分散式設定系統可讓每個服務套件的部分內容,透過服務套件註冊資料庫獨立更新,如這裡所示。

Orchestrator 分散式設定圖

圖 1. 自動調度管理工具設定圖。

車輛獨立設定不會因原始設備製造商 (OEM) 或車輛而異。每個原始設備製造商 (OEM) 的所有車輛設定都相同。不同原始設備製造商 (OEM) 的車輛,其車輛專屬設定可能不同,但特定 OEM 製造的所有車輛,其設定可能相同。

快速參考指引

下表匯總本頁涵蓋的 Orchestrator 設定區域、執行階段屬性和偵錯指令:

功能或設定領域 重要屬性、結構定義和指令 區段
載入各套件和各 VM 的設定 從服務套件註冊資料庫載入每個套件的自動化調度管理中繼資料,並從 persist.sdv.orchestrator_config_path (從 ro.boot.sdv.orchestrator_config_path 初始化) 載入 VM 範圍的設定。 設定 APEX 和個別 VM 設定
服務套裝組合、群組和狀態規則 設定 ServiceBundleConfig 執行個體、VmConfig 群組階層、布林值 Condition 運算式和狀態優先順序 (destroyed > started > created)。 設定語法、群組對應和設定狀態
當機復原和 Health Monitor 報表 透過 retry_mapping (max_retries) 或 ro.boot.sdv.orchestrator.recovery.max_retries 控制重新啟動嘗試、分類 Lifecycle Manager 錯誤,並向 Health Monitor 回報生命週期和復原狀態。 當機復原和重新啟動策略
端對端設定範例 車輛、電源和自訂模式的完整服務套件和 VM 層級自動化調度管理設定範例。 完整設定範例
平行處理和啟動時間排序 使用 ro.boot.sdv.max_bundles_management_threads (預設為 12) 調整並行 Lifecycle Manager 呼叫和繫結器執行緒,並使用 ro.sdv.orchestrator.state.ready 排序代理程式啟動。 設定套件管理平行處理和啟動時間最佳化
車輛、動力和自訂模式 使用 VPM 電源和車輛狀態、透過 CustomStateService.SetCustomState 傳播 OEM 自訂模式,並處理 SHUTDOWN_CANCELLED 電源轉換取消。 Orchestrator 使用的模式
執行階段檢查 (dumpsys) 使用 adb shell dumpsys com.google.sdv.ISdvAgent/orch 和 dumpsys google.sdv.lifecycle.ILifecycleManager/default 檢查啟用模式、模式佇列和要求的執行個體狀態。 偵錯工具

設定 APEX

在執行階段,Orchestrator 會前往服務套件註冊資料庫,擷取每個服務套件的 SDV 自動化調度管理,並載入及剖析每項設定。詳情請參閱「自動化調度管理中繼資料」。

個別 VM 設定

Orchestrator 啟動時,會載入並剖析 VM 設定 (如有)。這個設定檔的絕對路徑是透過系統屬性 persist.sdv.orchestrator_config_path 和 ro.boot.sdv.orchestrator_config_path 指定。

系統會根據下列階層,在啟動時決定 VM 設定檔路徑:

  1. 系統會檢查 persist.sdv.orchestrator_config_path 屬性。如果該變數有值,系統就會使用該路徑。這個值會在重新啟動後保留,或在執行階段設定。

  2. 如果 persist.sdv.orchestrator_config_path 為空白,系統會檢查 ro.boot.sdv.orchestrator_config_path 屬性。如果 ro.boot.sdv 屬性有值,該路徑會複製到 persist 屬性,並用於目前和日後的所有啟動作業 (除非遭到覆寫)。

persist.sdv.orchestrator_config_path

persist.sdv.orchestrator_config_path 是 SDV 調度管理代理用來取得設定檔路徑的主要屬性。這是永久屬性,也就是說,其值會在裝置重新啟動時儲存。您可以在執行階段變更值,這對測試或特定情境 (例如端對端測試) 很有幫助。

您可以在執行階段使用 setprop 指令設定值,也可以在建構階段使用 makefile (副檔名為 .mk) 或資源指令碼檔案 (副檔名為 .rc) 設定值。

在執行階段設定屬性

在執行階段設定屬性,有助於測試或進行暫時變更,因為系統重新啟動後仍會保留該值:

adb root
adb shell setprop persist.sdv.orchestrator_config_path {$path_to_file}.textproto

在建構時設定屬性

如要將這項屬性設為裝置建構設定的一部分,請在產品或主機板的 makefile 中新增一行。這項功能很適合用來為新裝置映像檔設定預設值。

# Add this line to a product's or device's .mk file
PRODUCT_PROPERTY_OVERRIDES += persist.sdv.orchestrator_config_path={$path_to_file}.textproto

您也可以在資源指令碼檔案中設定這項屬性:

# Add this line to an .rc file
on {$property}
    setprop persist.sdv.orchestrator_config_path {$path_to_file}.textproto

ro.boot.sdv.orchestrator_config_path

ro.boot.sdv.orchestrator_config_path 是開機時唯讀屬性,用於提供 persist.sdv.orchestrator_config_path 屬性的初始值。如果系統啟動時 persist.sdv.orchestrator_config_path 為空白,系統會將 ro.boot.sdv.orchestrator_config_path 的值複製到該屬性。設定 persist.sdv.orchestrator_config_path 後,後續啟動時,這項屬性不會覆寫該值。

您可以使用 bootconfig 或核心 cmdline 設定 ro.boot.sdv.orchestrator_config_path。

檔案格式

以 .textproto 格式 (例如結構化文字) 定義自動化調度管理設定,以便在執行階段載入新設定。

設定語法

本節說明設定語法。

服務套裝組合

每個服務套件都必須使用服務套件設定定義,以便在 Orchestrator 中識別套件,並用於處理套件執行個體的生命週期。服務套件設定會定義:

  • InstanceToGroupMapping 可讓您在群組中加入服務套件的執行個體,以便在相同服務套件的執行個體之間建立依附元件。

  • InstancesStates 定義服務套件執行個體的不同狀態。

  • InstancesStateConfiguration 定義了當條件評估為 true 時,服務套件執行個體必須設定的狀態 (來自 InstancesStates)。

  • ServiceBundleConfig 包含特定服務套件及其執行個體的相關資訊。其中包含套件的 InstanceToGroupMapping 和 InstancesStateConfiguration。

  • CustomModes 定義套件可發布的自訂模式清單。CustomModes 可防止未經授權的套件修改自訂模式的值。這個欄位為選填,因為服務套件可能不會發布至任何自訂模式。詳情請參閱「自訂模式」。

必要的套裝組合設定

套件設定至少會提供下列屬性:

service_bundle_config {
    package_name: "package_name"
    service_bundle_name: "service_bundle_name"

    instance: "instance_1"
    instance: "instance_n"
}

這項宣告會定義 n 服務套件例項,並提供各自的 FQIN:

vm_name.package_name.service_bundle_name.instance_1
…
vm_name.package_name.service_bundle_name.instance_n

設定中未明確宣告 VM 名稱。由於設定是依 VM 定義,因此 VM 名稱一律是部署設定檔的 VM 名稱,且自動調度管理代理程式已知該名稱。

設定執行個體

宣告服務套件執行個體不會產生任何影響。如要由 Orchestrator 執行,必須設定執行個體。舉例來說,Orchestrator 必須知道執行個體應在哪些條件 (或 VM 或車輛狀態) 下執行。如要設定執行個體,應透過下列方式定義設定狀態:

  • condition 是 VM 或車輛狀態的運算式,應進行評估。

  • instances_states 是每個執行個體的一組狀態,如果條件評估為 true,則應套用這些狀態。

詳情請參閱「條件」。

service_bundle_config {
    package_name: "oem.package"
    service_bundle_name: "OemApplication"

    instance: "adaptive_light"
    instance: "reserve_light"

    state {
        condition {
            power_state: "ON"
        }

        instances_states {
            started: "adaptive_light"
            created: "reserve_light"
        }
    }
}

執行個體與群組的對應關係

您也可以將服務執行個體納入服務群組,藉此設定服務執行個體。在服務套件設定層級,您可以將執行個體新增至群組。接著,您可以在 VM 設定層級設定群組。詳情請參閱下一節和「服務套裝組合」。

service_bundle_config {
    package_name: "oem.package"
    service_bundle_name: "OemApplication"

    instance: "fog_front_light"
    instance: "fog_rear_light"
    instance: "turn_signal_light"
    instance: "light_flasher_display"

    # Declare that fog_light contains fog_front_light and fog_rear_light.
    group_mapping {
        group: "fog_light"
        instance: "fog_front_light"
        instance: "fog_rear_light"
    }

    # Declare that flasher_light contains turn_signal_light and light_flasher_display.
    group_mapping {
        group: "flasher_light"
        instance: "turn_signal_light"
        instance: "light_flasher_display"
    }
}

Proto 結構定義

以下是 Proto 配置範例:

// Service bundle configuration.
//
// Defines service bundle data, its instances and configuration for instances
// states depending on the state of the system
message ServiceBundleConfig {
  // Required. Name of the service bundle.
  string service_bundle_name = 1;

  // Required. Package name of the service bundle.
  string package_name = 2;

  // Required. Service instances.
  repeated string instance = 3;

  // Configuration for instances states depending on the state of the system.
  repeated InstancesStateConfiguration state = 4;

  // Mapping of groups to their member service instances.
  repeated InstanceToGroupMapping group_mapping = 5;

  // Custom modes that this service bundle is allowed to set.
  repeated string custom_mode = 6;

  // Defines the retry policies for specific instances.
  // If multiple mappings target the same instance, the one with the highest `max_retries`
  // value takes precedence. This applies across all configuration files.
  repeated InstanceToRetryMapping retry_mapping = 7;
}

// Mapping of instances to their retry configuration.
message InstanceToRetryMapping {
  // Required.
  //
  // Name of the instances for which the given retry configuration is applied.
  repeated string instance = 1;

  // Required.
  //
  // The configuration that defines the restart and retry strategy for the instances.
  RetryConfiguration retry_config = 2;

  // Configuration for retry and restart.
  // This configuration is applied after a failure on a transition or after the bundle instance
  // has crashed. Upon a successful operation, the retry counter are reset to max_retries. This
  // configuration can be applied to any service bundle, not only the monitored ones. If the
  // configuration is not provided or none of the optional fields are filled, the default behavior
  // stated is applied (the value from `ro.boot.sdv.orchestrator.recovery.max_retries`
  // or zero if not set).
  message RetryConfiguration {
    // The number of times a retry/restart operation can be performed.
    // Defines the number of times the Orchestrator retries a transition
    // after a transient failure or after a bundle crash notification.
    // This applies to creating, starting and destroying operations.
    // The retry count resets to max_retries after a successful operation.
    // If not set, the default configured value in the
    // `ro.boot.sdv.orchestrator.recovery.max_retries` is used, or-if not set-
    // it fallbacks to zero.
    optional uint32 max_retries = 1;
  }
}

// Mapping of groups to their member service instances.
message InstanceToGroupMapping {
  // Required. Names of groups to which members are added.
  //
  // Group behavior is defined in VM configuration.
  repeated string group = 1;

  // Required. Names of instances to be included in the groups.
  //
  // Can reference only instance defined in the same config file.
  repeated string instance = 2;
}

// Describes the state the service instances should be in after the state is executed.
//
// If there is no valid configuration for the instance in the specific system state, such instance is transitioned to the "destroyed" state.
//
// For the GroupsStates definition to be useful, at least one item should be present in any of the fields.
message InstancesStates {
  // Names of the instances that must be in a "created" state.
  repeated string created = 1;

  // Names of the instances that must be in a "started" state, overrides "created" state.
  repeated string started = 2;

  // Names of the instances that must not run, overrides all other states.
  repeated string destroyed = 3;
}

// Configuration for instances states depending on the state of the system.
message InstancesStateConfiguration {
  // Condition for the system state under which the related instances states should be executed by Orchestrator.
  //
  // If omitted, the related instances states are always executed.
  Condition condition = 1;

  // Required. States of service bundle instances to be executed by Orchestrator if the condition is true.
  InstancesStates instances_states = 2;
}

VM 層級設定

VM 設定可定義群組對應和群組設定。可用於在 VM 層級建立服務套件之間的依附元件模型,進而靈活修改多個服務套件的狀態。群組的所有執行個體都會進入指定狀態。

Orchestrator 不保證狀態變更的執行順序。Orchestrator 會將每個執行個體升級至指定狀態。

在任何設定部分使用 group 名稱,即可隱含宣告群組。例如執行個體與群組的對應關係、群組與群組的對應關係,以及群組設定狀態。

群組對應

群組可以包含其他群組。只要宣告 group_1 包含 subgroup_2,就能有效地將 subgroup_2 中的所有服務執行個體新增至 group_1。

例如:

# Declare that body contains fog_light and flasher_light.
group_mapping {
    group: "body"
    subgroup: "fog_light"
    subgroup: "flasher_light"
}

設定群組

宣告群組不會產生任何影響。如要由自動化調度管理工具執行,必須設定群組。舉例來說,Orchestrator 必須知道群組應在 VM 或車輛的哪些條件或狀態下執行。

您可以透過類似服務執行個體的方式設定群組,也就是使用設定狀態。唯一的差別在於語法中使用 groups_states,而非 instances_states:

state {
    condition {
        power_state: "ON"
    }

    groups_states {
        started: "Body"
        started: "Adas"
    }
}

Proto 結構定義

以下是 Proto 結構定義範例:

// VM configuration.
//
// Defines group-to-group mappings and configuration for groups
// states depending on the state of the system.
//
// Configurations of service bundles can also be defined in VM configuration (as well as in a separate configuration file).
message VmConfig {
  // Group to member groups mapping.
  repeated GroupToGroupMapping group_mapping = 1;

  // Configuration of group states.
  repeated GroupsStateConfiguration state = 2;

  // Required. We also allow to configure individual service bundles in the VM config, to simplify development and migration from the monolithic configuration.
  repeated ServiceBundleConfig service_bundle_config = 3;
}

// Mapping of groups to their member groups.
message GroupToGroupMapping {
  // Required. Names of groups to which members are added.
  repeated string group = 1;

  // Required. Names of member groups to be included in the groups.
  repeated string subgroup = 2;
}

// Describes the state the service instance groups should be in after the state is executed.
//
// If group configuration is valid in a specific system state, the configured state is applied to
// all group members. After that, the normal service instance configuration rules still apply:
// - "destroyed" > "started" > "created" precedence
// - not configured means the instance should be moved to the default state
//
// For the GroupsStates definition to be useful, at least one item should be present in any of the fields.
message GroupsStates {
  // Names of the groups that must be in a "created" state.
  repeated string created = 1;

  // Names of the groups that must be in a "started" state, overrides "created" state.
  repeated string started = 2;

  // Names of the groups that must not run, overrides all other states.
  repeated string destroyed = 3;
}

// Configuration for group states depending on the state of the system.
message GroupsStateConfiguration {
  // Condition for the system state under which the related group states should be executed by  Orchestrator.
  //
  // If omitted, the related groups states are always executed.
  Condition condition = 1;

  // Required. States of service bundle groups to be executed by Orchestrator if the condition  is true.
  GroupsStates groups_states = 2;
}

設定狀態

設定狀態 (狀態) 定義服務執行個體或群組何時啟動、停止或刪除,並由 conditions 和 instances_states (套件設定) 和 groups_states (VM 設定) 組成。

條件

條件可讓模型在評估為 true 時,套用定義的例項狀態。條件具有下列特性:

  • 根據支援的信號 (例如電源、車輛和自訂模式),任意複雜的布林運算式 (由 and 或 not 運算式組成)。

  • (選用) 沒有條件的設定狀態一律為有效,也就是說,其評估結果為 true

執行個體狀態和群組狀態

instances_states 和 groups_states 具有這些特性。

  • 指定調度管理代理需要哪些狀態,才能套用至指定執行個體或群組,假設狀態為 active

  • 將狀態套用至群組時,狀態會套用至群組中的每個服務套裝組合執行個體。執行個體進入該狀態時,不會套用任何順序。

支援的州包括:

  • 呼叫 Service::on_start 後,started。

  • created

    • 在呼叫 Service::new 之後,但在呼叫 Service::on_start 之前。

      或

    • 在呼叫 Service::on_stop 之後,但在呼叫 Service::drop 之前。

  • 呼叫 Service::drop 後,destroyed。

規則集

設定狀態可以是「有效」或「無效」,視條件而定。您可以隨時啟用多個狀態。當自動化調度管理代理收到信號更新時,系統會先評估「所有」設定狀態,再修改服務套件的生命週期。系統會根據下列規則評估服務執行個體狀態:

  • 如果服務執行個體不適用任何有效狀態,就會遭到刪除。

  • 如果一或多個模式同時啟用,系統會依下列順序套用:

    1. destroyed 具有絕對優先權。
    2. started 的優先順序高於 created。

Proto 結構定義

以下是 Proto 結構定義範例:

// A root boolean condition.
message Condition {
  // Required.
  oneof root {
    // VPM power state condition.
    string power_state = 1;
    // VPM vehicle state condition.
    string vehicle_state = 2;
    // Custom mode state condition.
    CustomState custom_state = 3;
    // Negation of a nested condition.
    Condition not = 4;
    // Logical 'and' between conditions grouped in expression.
    Expression and = 5;
    // Logical 'or' between conditions grouped in expression.
    Expression or = 6;
  }
}

// Representation of Custom state condition.
//
// Custom mode(s) are defined by the OEM and are not standardized by the platform, in contrast with
// VPM modes (i.e. power and vehicle mode).
message CustomState {
  // Custom mode being checked.
  string mode = 1;
  // State of the custom mode.
  string state = 2;
}

// A set of conditions united under an 'and' or 'or' expression.
//
// Evaluation type ('and' or 'or') depends on the field in [Condition]/[Expression], where the
// expression is being used.
//
// At least one value in at least one of the fields is required.
message Expression {
  // VPM power state condition.
  repeated string power_state = 1;
  // VPM vehicle state condition.
  repeated string vehicle_state = 2;
  // Custom mode state condition.
  repeated CustomState custom_state = 3;
  // Negation of a nested condition.
  repeated Condition not = 4;
  // Logical 'and' between conditions grouped in expression.
  repeated Expression and = 5;
  // Logical 'or' between conditions grouped in expression.
  repeated Expression or = 6;
}

當機復原和重新啟動策略

Orchestrator 提供強大的機制,可處理服務套件當機和生命週期轉換失敗的問題。Orchestrator 具備服務狀態的整體檢視畫面,並可管理模式轉換,因此最適合用來執行重新啟動和重試策略。Lifecycle Manager (LM) 會透過繫結器終止通知,向 Orchestrator 回報服務套件停止運作。為避免對 LM 進行不必要的繫結器呼叫,Orchestrator 會快取每個套件的最後狀態 (無論是否成功),且如果最後已知狀態與新要求的狀態相同,則不會重新套用轉換。

重試設定

您可以使用 retry_mapping,在 Orchestrator 設定中定義每個執行個體的重新啟動和重試策略。如果未在設定中設定 max_retries,系統會從 ro.boot.sdv.orchestrator.recovery.max_retries 系統屬性取得預設值。如未設定這項屬性,值會預設為 0。

  • max_retries:定義在暫時性失敗或套件當機通知後,自動化調度管理工具重試轉換的次數。作業成功或處理新模式後,重試計數器會重設為 max_retries 的值。如果有多個對應項目指定同一個執行個體,則以 max_retries 最高的對應項目為準。

設定範例

service_bundle_config {
  package_name: "oem.package"
  service_bundle_name: "OemApplication"
  instance: "fog_front_light"
  instance: "fog_rear_light"

  # Defines the restart configuration mapping for specific instances.
  retry_mapping {
    instance: "fog_front_light"
    instance: "fog_rear_light"
    retry_config {
      max_retries: 3
    }
  }
}

復原行為

Orchestrator 的重新啟動和重試邏輯可妥善管理多種失敗情況:

  • 正常作業當機:如果服務套件在執行時當機,Orchestrator 會套用重新啟動策略,並根據剩餘的重試次數,嘗試將套件恢復到上次要求的狀態。
  • 模式轉換期間當機:如果套件在強制執行新模式時當機,重新啟動要求會排入佇列,並在稍後處理。要求處理完畢後,Orchestrator 會檢查執行個體的最後一個狀態,只有在執行個體並非處於最後要求的狀態 (來自最後一次模式轉換) 時,才會套用重新啟動。
  • 復原期間的新模式:如果 Orchestrator 在重新啟動套件 (或在要重新啟動的執行個體佇列中) 時收到轉換至新模式的要求,就會取消進行中的復原作業。新的模式轉換會接管,重試計數器會重設,允許對新的目標狀態進行一組新的嘗試。

Orchestrator 會區分 Lifecycle Manager 傳回的不同錯誤類型,以決定重試策略:

  • 暫時性錯誤 (SERVICE_NOT_FOUND、OPERATION_FAILED、INTERNAL_ERROR):Orchestrator 會重試作業,不採取任何特殊清理動作。
  • 持續性錯誤 (VALUE_CORRUPTED、INVALID_ARGUMENT):Orchestrator 會假設服務套件可能處於損毀狀態,並嘗試終止服務執行個體,然後再重試作業,確保能重新啟動。
  • 永久錯誤 (PERMISSION_DENIED):系統不會重試作業,且套件會視為處於無法復原的狀態。

如果 Lifecycle Manager 當機,所有服務套件程序都會遺失。由於實際狀態不明,Orchestrator 會撤銷每個執行個體,並套用重新啟動策略,利用剩餘的重試次數,將每個執行個體帶到上次要求的狀態。

為避免套件因反覆異常終止或失敗而陷入無限復原迴圈,只有在生命週期作業成功或要求新的模式轉換時,重試計數器才會重設為 max_retries。如果套件因連續失敗 (例如轉換失敗後發生當機) 而用盡重試次數,則在重試計數器重設之前,系統不會重新啟動。

向健康狀態監控工具回報狀態

Orchestrator 會公開內部繫結器介面,Health Monitor (HM) 會註冊到該介面,以便持續接收所有服務套件狀態的更新。透過這個介面,Orchestrator 會主動回報以下兩項資訊:

  • 生命週期狀態:根據目前設定和有效模式,執行個體應處於的狀態 (例如已啟動、已建立或已刪除)。
  • 復原狀態:達到預期生命週期狀態的狀態,指出執行個體是否可運作、目前是否在失敗後重試,或在用盡所有重試次數後仍無法復原。

系統會回報所有執行個體的這項資訊,包括未註冊進行心跳監控的執行個體。HM 會使用這項資訊實作 API,回報 VM 的狀態。您可以在「Health monitoring」中瞭解詳情。

範例

本節提供範例,說明如何設定狀態條件。

基礎服務範例
  • 沒有條件,因此一律啟用。
  • 啟動單一服務執行個體。
state {
  # Note: This state has no condition, hence its actions are valid throughout the lifetime of the program
  instances_states { started: "ServiceBundleName" }
}
空調應用程式範例
  • 條件:custom_state != occupancy.OCCUPANCY_EMPTY || custom_state == preheat.PREHEAT_ON時啟用。

  • 將多個空調相關服務執行個體宣告為 started。

state {
  condition {
    or {
      # I.e. when the vehicle is occupied (for example, by _DRIVER / _NON_DRIVER / _PET)
      not {
        custom_state {
          mode: "occupancy"
          state: "OCCUPANCY_EMPTY"
        }
      }
      custom_state {
        mode: "preheat"
        state: "PREHEAT_ON"
      }
    }
  }

  # HVAC-related services
  instances_states {
    started: "HvacTemperatureCommand"
    started: "TempSensorDriverZone"
    started: "TempSensorPassengerZone"
    started: "RefrigerantLoop"
  }
}
省電範例
  • 條件:custom_state == system_power.SYSTEM_POWER_LOW && custom_state == range_ext.RANGE_EXT_ON時啟用。

    這個狀態可視為省電狀態。

  • 將一個空調相關服務執行個體宣告為 destroyed。

  • 在本範例中,當 SYSTEM_POWER_LOW 和 RANGE_EXT_ON 模式處於啟用狀態時,HVAC 應用程式會在沒有 RefrigerantLoop 服務執行個體的情況下執行:

    state {
      condition {
        and {
          custom_state {
            mode: "system_power"
            state: "SYSTEM_POWER_LOW"
          }
          custom_state {
            mode: "range_ext"
            state: "RANGE_EXT_ON"
          }
        }
      }
    
      # Disable services with high power consumption
      instances_states { destroyed: "RefrigerantLoop" }
    }
    
Life onboard 範例
  • 條件:如果 power_state == ON && vehicle_state == LIFE_ON_BOARD,則為有效。

    這個狀態可以視為「有人在車內,且車輛已啟動」。

  • 宣告溫度感應器正在運作。

  • 有人在車內時,系統會監控溫度等項目,確保安全。

state {
  condition {
    and {
      power_state: "ON"
      vehicle_state: "LIFE_ON_BOARD"
    }
  }

  # Temperature monitoring services
  instances_states {
    started: "TempSensorDriverZone"
    started: "TempSensorPassengerZone"
  }
}

完整設定範例

本節提供完整範例,包含:

  • 服務套裝組合層級的原型設定,介紹含有兩個執行個體的服務套裝組合,每個執行個體都是群組的一部分

  • VM 層級的 Proto 設定,可根據模式導入與群組互動的邏輯

服務套裝組合層級設定

# proto-file: //system/software_defined_vehicle/orchestration/distributed_config/src/protos/service_bundle_config.proto
# proto-message: ServiceBundleConfig

package_name: "oem.package"
service_bundle_name: "OemApplication"
instance: "fog_front_light"
instance: "fog_rear_light"
instance: "turn_signal_light"
custom_mode: "FOG"
custom_mode: "TURN"

group_mapping {
    group: "fog_light"
    instance: "fog_front_light"
    instance: "fog_rear_light"
}

group_mapping {
    group: "flasher_light"
    instance: "turn_signal_light"
}

state {
    condition {
        power_state: "ON"
    }

    instances_states {
        created: "turn_signal_light"
        destroyed: "fog_front_light"
        destroyed: "fog_rear_light"
    }
}

VM 層級設定

# proto-file: //system/software_defined_vehicle/orchestration/distributed_config/src/protos/vm_config.proto
# proto-message: VmConfig

group_mapping {
    group: "lights"
    subgroup: "fog_light"
    subgroup: "flasher_light"
}

state {
    condition {
        custom_state {
            mode: "FOG"
            state: "ON"
        }
    }
    groups_states {
        started: "fog_light"
    }
}

state {
    condition {
        custom_state {
            mode: "TURN"
            state: "RIGHT"
        }
    }
    groups_states {
        started: "flasher_light"
    }
}

state {
    condition {
        vehicle_state: "SUSPEND_TO_RAM_ENTER"
    }
    groups_states {
        created: "lights"
    }
}

設定套件管理平行處理

ro.boot.sdv.max_bundles_management_threads 系統屬性是重要的調整參數,用於控制服務套件生命週期作業期間的效能和資源消耗。這項設定會定義服務套件交易的平行處理數量上限,並直接影響兩項核心服務:

  1. Orchestration Engine:這項服務會讀取屬性,判斷 Orchestrator 可對 Lifecycle Manager 發出多少並行呼叫 (例如 startService、stopService)。在啟動和模式轉換期間,許多套件可能會同時變更狀態,因此這項功能對於效能至關重要。

  2. Lifecycle Manager:這項服務會使用屬性值計算 Binder 執行緒集區的大小,該集區負責處理所有傳入要求。這可確保 LM 有足夠的執行緒,可處理來自 Orchestrator 的並行要求。

如未設定這項屬性,兩項服務的預設值均為 12。

設定方法

如要設定這項屬性,請在裝置的 BoardConfig.mk 檔案中,將屬性新增至 BOARD_BOOTCONFIG 變數。這可確保每次裝置啟動時都會套用該值。

BOARD_BOOTCONFIG += \
    androidboot.sdv.max_bundles_management_threads=8

如要變更裝置的值,請在適當的 BoardConfig.mk 檔案中修改這一行,然後重新建構。

啟動時間最佳化

ro.sdv.orchestrator.state.ready 是 write-once 布林值屬性,屬於開機時間效能最佳化策略的一部分。這表示 Orchestration 代理程式已完成初始化,可以開始管理服務套件的生命週期。其主要目的是控制其他 SDV 代理程式的啟動順序,優先啟動 Orchestrator 及其代管服務套件。

  • 設定者:自動化調度管理代理。
  • 時機:在啟動程序期間執行一次。
  • 用途:init 系統會使用這項屬性,控制大多數 SDV 代理程式 (更新管理工具、VSIDL 供應商、健康監測、服務探索、資料通道、RPC、VPM 和遙測) 的啟動順序。提早啟動 Orchestrator 並讓其他代理程式等待這項屬性,系統就能確保 Orchestrator 開始執行啟動服務套件的重要工作,而不會爭奪系統資源。

效能

系統啟動時,如果同時啟動所有代理程式,可能會導致資源爭用,拖慢整體啟動程序。為減輕這個問題,系統會使用系統屬性強制執行依序啟動順序:

  1. 服務套件註冊資料庫:首先啟動,載入所有服務套件中繼資料。
  2. Lifecycle Manager 和 Orchestrator:這些核心代理會在登錄檔準備就緒後立即啟動。提早啟動至關重要,因為這可讓 Orchestrator 開始評估設定,並準備立即啟動服務套件。
  3. 其他 SDV 代理:在自動調度管理工具準備就緒後,才會啟動。

這種受控序列可確保 Orchestrator 優先使用系統資源,盡早啟動服務套件,進而加快系統啟動速度、提高確定性和效率。

Orchestrator 使用的模式

自動調度管理代理會持續訂閱 VPM 傳輸的車輛和電源模式。在 Orchestrator 與車輛和電源管理 (VPM) 系統之間建立初始連線後,Orchestrator 會將下列布林值系統屬性設為 true:

  • sdv.orchestrator.bootup.power_mode.ready

  • sdv.orchestrator.bootup.vehicle_mode.ready

調度管理代理會以設定檔為參考依據,根據收到的模式目前值,動態計算應處於執行狀態的服務套件組合。接著,Orchestrator 會與生命週期管理工具通訊,發出不同指令,讓服務套件的實際狀態與計算出的目標狀態一致。

車輛和電源狀態

車輛模式和電源管理 (VPM) 代理程式可讓 SDV 元件瞭解車輛目前的狀態,例如操作模式 (例如停車或駕駛) 和電源狀態 (例如開啟和暫停)。Orchestrator 會評估這些值,根據 Orchestrator 設定定義應執行的服務套件。詳情請參閱「車輛和電源管理」。

自訂模式

由於車輛模式數量眾多,我們無法為所有模式建立模型。每個原始設備製造商 (OEM) 都有不同的需求,而標準化車輛模式無法滿足所有 OEM 的用途。因此,我們支援原始設備製造商 (OEM) 專屬模式,稱為「自訂模式」。這些模式不會擴充現有的車輛和電源模式。而是提供定義新模式的方法。

功能:

  • 全域範圍:自訂模式為全域模式,會統一套用至 Orchestrator 管理的所有 VM。

  • 組合結構:每項自訂模式變更都包含兩個元素:

    • 名稱:原始設備製造商 (OEM) 選取用來代表自訂模式的專屬 ID。

    • 值:自訂模式的目前狀態,如果未設定值,則可以是 UNDEFINED。

  • Orchestrator 角色:Orchestrator 是自訂模式值的被動接收者。

  • 服務套件角色:每個服務套件都可以擁有多個自訂模式,並可將新值發布至任何模式。多個服務套件可以擁有相同的自訂模式,也就是說,自訂模式可以接收來自不同來源的新值。

  • 驗證責任:原始設備製造商 (OEM) 負責確保狀態轉換有效。Orchestrator 會接受任何新值。

預估特徵:

  • 預估數量:電源和車輛模式會管理大多數服務套件的生命週期,自訂模式則扮演輔助角色。我們預期自訂模式的數量級為數十個,而非數百個。

  • 預估時間:模式不會定期傳送。相反地,模式是由事件驅動,並由特定動作觸發,例如開門、啟動停車程序、開始充電週期,以及其他由原始設備製造商 (OEM) 定義的重要類似事件。

自訂模式設計可讓您靈活定義及管理特定模式,同時讓 Orchestrator 保持與基礎狀態機邏輯無關。

支援的模式

為確保服務套件只會發布至其擁有的自訂模式,每個服務套件都必須在 Orchestrator 設定中明確宣告擁有的自訂模式清單,該設定可在本機 VM 中透過服務套件註冊資料庫取得。如果嘗試發布至未宣告的自訂模式,系統會捨棄該操作。

如要宣告服務套件可發布 (因此擁有) 的自訂模式,請使用下列內容擴充 service_bundle_config proto 結構定義:

// Service bundle configuration.
//
// Defines service bundle metadata, its instances, and configuration for instances
// lifecycle states depending on the state of the vehicle.
message ServiceBundleConfig {
      [...]

    // The list of custom modes that this service bundle publishes.
    repeated string custom_mode = 5;
}

根據模式設定套件

現有的 Orchestrator proto 設定 (Condition 元件) 支援根據自訂模式操控服務套件:

message Condition {
  oneof root {
    string power_state = 1;
    string vehicle_state = 2;
    CustomState custom_state = 3;
    Condition not = 4;
    Expression and = 5;
    Expression or = 6;
  }
}

message CustomState {
  // Custom mode being checked.
  string mode = 1;
  // State of the custom mode.
  string state = 2;
}

Proto 範例

以下範例說明如何根據 TURN 和 FOG 狀態,設定要啟動的服務套件執行個體:

service_bundle_config {
package_name: "oem.package"
service_bundle_name: "OemApplication"
instance: "flasher_light"
// Service bundle is allowed to set values for the TURN mode
custom_mode: "TURN"
// Service bundle is allowed to set values for the FOG mode
custom_mode: "FOG"

state {
    condition {
        custom_state {
            mode: "TURN"
            state: "LEFT"
        }
    }
    instances_states {
        started: "flasher_light"
    }
}

state {
    condition {
        custom_state {
            mode: "FOG"
            state: "ON"
        }
    }
    // Group assumed to be defined containing all FOG lights instances.
    groups_states {
        started: "fog_lights"
    }
}

}

設定新的自訂模式

設定新的自訂模式值時,首先會由服務套件將所需的值傳送至在本機上執行的 Orchestrator (位於同一個 VM)。接著,Orchestrator 會驗證服務套件是否具備發布至指定自訂模式所需的權限,並參照 .textproto 中定義的設定,判斷是否應將值傳播至其他 VM。傳播完成後,每個 Orchestrator 都會檢查其設定,找出應變更狀態的服務套件清單。

RPC

在每個 VM 上執行的每個 Orchestrator 都會建立 RPC 伺服器,用於監聽新的自訂模式值。每個想要更新自訂模式的服務套件,都必須建立伺服器的 RPC 用戶端。系統會強制執行 ACL,防止未經授權的套件連線至伺服器。

透過 RPC 設定新值的 proto 定義如下:

syntax = "proto3";

import "google/protobuf/timestamp.proto";

package com.sdv.google.Orchestrator;

// Representation of the request used by service bundles to update a custom mode.
// Service bundles are permitted to update only the custom modes specifically designated
// for them within the Orchestrator configuration.
message SetCustomStateRequest {
  // Required.
  // The name of the custom mode.
  // The mode string can not be longer than 56 characters and can only contain
  // letters, numbers, dashes, dots and underscores: [a-zA-Z0-9_-.].
  // No other special character nor spaces should be present in the mode.
  string mode = 1;

  // Required.
  // The new value for the custom mode.
  // The value string can not be longer than 56 characters and can only contain
  // letters, numbers, dashes, dots and underscores: [a-zA-Z0-9_-.].
  // No other special character nor spaces should be present in the value.
  string value = 2;

  // Required.
  // The timestamp in which the new custom mode value was set. This is used to
  // prevent race conditions whenever different service bundles in different
  // VMs want to set a new value for the same custom mode.
  // We use this timestamp to order the requests and we promise eventual
  // consistency: while temporary inconsistencies may occur, the system will
  // eventually converges to the correct state.
  .google.protobuf.Timestamp timestamp = 3;
}

// Representation of the set custom state response.
message SetCustomStateResponse {}

// Orchestrator interface for service bundles that update the value of a
// custom mode.
// When a new value is received, it is propagated to Orchestrators running on
// other VMs.
service CustomStateService {
  // Updates the value for the custom mode.
  // Returns the error:
  // - PermissionDenied: the service is not authorized to update the custom mode.
  // - InvalidArgument: the provided mode and/or value are not valid.
  rpc SetCustomState(SetCustomStateRequest) returns (SetCustomStateResponse) {};
}

取消電源轉換

Orchestrator 可透過 SHUTDOWN_CANCELLED 電源模式 (由 VPM 傳送至 Orchestrator),取消進行中的電源轉換。

以下列 Orchestrator 設定為例:

state {
    condition {
        power_state: "SUSPEND_TO_RAM_ENTER"
    }
    instances_states {
        started: "instance-1"
        started: "instance-2"
        started: "instance-3"
    }
}

收到 SHUTDOWN_CANCELLED 模式時,Orchestrator 的行為會由兩種主要情境決定。在這兩種情況下,SHUTDOWN_CANCELLED 電源模式都會附加至佇列結尾。接著,系統會在佇列元素用完後執行 SHUTDOWN_CANCELLED。

情境 1:目前進行中的模式是電源模式

如果 Orchestrator 正在執行電源模式更新,則會要求取消進行中的模式。雖然 Lifecycle Manager 本身不支援取消進行中的轉換,但 Orchestrator 會確認沒有啟動新的服務套件要求。

範例:如果前一個範例設定中的 instance-1 在收到 SHUTDOWN_CANCELLED 模式時正在啟動,instance-1 會完成啟動。不過,instance-2 和 instance-3 不會繼續轉換至啟動狀態。

情境 2:處理佇列中存在電源模式

如果 Orchestrator 正在處理非電源模式更新,且待執行模式佇列中有電源要求,系統會從佇列中移除電源轉換。這可避免執行。

範例:使用前一個範例中的設定,如果 Orchestrator 正在處理與電源無關的更新 (例如車輛更新),且 SUSPEND_TO_RAM_ENTER 位於佇列中,則收到 SHUTDOWN_CANCELLED 會導致所有執行個體 (instance-1、instance-2、instance-3) 都不會啟動。

導入範例

如果用戶端想使用中介軟體產生的程式碼,建立 RPC 伺服器的用戶端,則目錄可能如下所示:

# proto-file: //system/software_defined_vehicle/vsidl/language/src/protos/sdv/vsidl/v1/syntax.proto
# proto-message: VsidlEntry

package: "package_name"

service_bundle {
    name: "service_bundle_name"

    client {
        service: "com.android.sdv.orchestrator.CustomStateService"
    }
}

產生程式碼時,您必須將依附元件新增至 Orchestrator 目錄:

--dependency-catalog-path orchestration/engine/stable/vsidl/*

用於傳送新值的用戶端程式碼如下所示:

let fqin = ServiceFqin::builder()
        .sdv_vm_name("vm_name")
        .sdv_package_name("package_name")
        .service_bundle_name("service_bundle_name")
        .service_instance_name("instance_name")
        .build()
        .unwrap();
let context_ref = ContextRef::create(fqin);
let comms = Arc::new(SdvComms { context: context_ref });
// service_bundle_name is the bundle generated with middleware code that defines
// the RPC client to "com.android.sdv.orchestrator.CustomStateService".
let client = service_bundle_name::new(comms).await.unwrap();
let rpc_client = client
        .create_rpc_client::<Client>(
            UnitName::builder()
                .vm_name(comms.context.get_self_fqin().get_sdv_vm_name())
                .package_name("com.android.sdv.orchestrator")
                .bundle_name("OrchestratorServiceBundle")
                .service_unit_name(Client::DEFAULT_UNIT_NAME)
                .build()
                .unwrap(),
            ClientOptions::default(),
        )
        .await;
let client = Arc::new(rpc_client.unwrap());
let request = SetCustomStateRequest {
mode: custom_mode_name,
value: custom_mode_value,
timestamp: MessageField::some(Timestamp::now()),
..Default::default()
};
let result = client.SetCustomState(&request).await;
// Process result

偵錯工具

調度管理代理支援 dumpsys 工具。只要在執行中的 SDV 執行個體上執行下列指令,即可叫用這項工具:

adb shell dumpsys com.google.sdv.ISdvAgent/orch

您可以使用這項工具偵錯,並深入瞭解 Orchestrator 代理的內部狀態。系統會顯示:

  • 目前模式狀態:查看使用中的車輛、電源和自訂模式。
  • 自訂模式發布者:找出哪些服務可以發布自訂模式 (以及發布至哪些模式)。
  • 各服務的必要狀態:根據預先定義的條件和目前模式,瞭解各服務套件的狀態。這有助於診斷服務未處於預期狀態的原因。
  • 模式強制執行狀態:清楚瞭解正在進行的強制執行模式,或上次強制執行的模式 (如果沒有正在進行的模式)。
  • 模式強制執行佇列:查看等待強制執行的模式。

例如:

AGENT NAME: SDV Agent dump - Orchestrator
AGENT FQIN: instance1:com.android.sdv.orchestrator.OrchestratorServiceBundle/default
AGENT STATE: See orchestrator state below.
----------------
----------------
INTERNAL STATE REPORTERS:

*NAME: Configuration state
*REPORT:
Active modes:
MODE                          VALUE                         TIMESTAMP (scs, ns)
Power                         POWER_OFF_EXIT                -
Vehicle                       VEHICLE_ON                    -
Custom("CHARGING")            ON                            1750757590 (scs) 466507459 (ns)
Custom("TIRE_PRESSURE")       front-left                    1750757570 (scs) 554522995 (ns)

Modes allowed to publish by bundle (FQIN: modes):
com.android.sdv.sample.orchestration/CustomModeControlBundle: CHARGING, TIRE_PRESSURE

Requested state for instances:
STATE          FQIN
Started        com.android.sdv.sample.orchestration/CustomModeControlBundle/always-started-instance
Started        com.android.sdv.sample.orchestration/OrchestratedServiceBundle/my-instance
Started        com.sdv.oem.sample.diagnostics/DiagnosticsSampleWithDataItem/instance
Started        com.sdv.oem.sample.diagnostics/DiagnosticsSampleWithEvent/instance
Started        com.sdv.oem.user_preferences/UserPreferencesServiceBundle/default
----------------
*NAME: Engine state
*REPORT:
Last mode enforced was Custom("CHARGING") with value "ON"

Next modes to process: []
----------------

如要進一步瞭解由 Orchestrator 管理的個別服務套件,請使用 Lifecycle Manager 的現有 dumpsys,如下所示:

dumpsys google.sdv.lifecycle.ILifecycleManager/default

這樣做可提供每項服務生命週期狀態的詳細資訊。結合 Orchestrator dumpsys 輸出內容和 Lifecycle Manager 的輸出內容,即可完整瞭解 VM 中服務套件的生命週期。