9 Ekim 2018 Salı

Power Management

Advanced Configuration and Power Interface (ACPI)
Açıklaması şöyle.
In a computer, the Advanced Configuration and Power Interface (ACPI) provides an open standard that operating systems can use to discover and configure computer hardware components, to perform power management by (for example) putting unused components to sleep, and to perform status monitoring. First released in December 1996, ACPI aims to replace Advanced Power Management (APM), the MultiProcessor Specification, and the Plug and Play BIOS (PnP) Specification.[1] ACPI brings the power management under the control of the operating system, as opposed to the previous BIOS-centric system that relied on platform-specific firmware to determine power management and configuration policies.
Internally, ACPI advertises the available components and their functions to the operating system kernel using instruction lists ("methods") provided through the system firmware (Unified Extensible Firmware Interface (UEFI) or BIOS), which the kernel parses. ACPI then executes the desired operations (such as the initialization of hardware components) using an embedded minimal virtual machine.
SetThreadExecutionState
Şöyle yaparız.
//sets the appropriate flags to prevent system to go into sleep mode.
SetThreadExecutionState(ES_CONTINUOUS|ES_SYSTEM_REQUIRED|ES_AWAYMODE_REQUIRED);

// This clears the flags and allows the system to sleep normally.
SetThreadExecutionState(ES_CONTINUOUS);
ES_CONTINUOUS 
Tek başına kullanılırsa bayrakları siler. Tek başına değilse belirtilen bayrakları atar.

ES_SYSTEM_REQUIRED
System Idle Timer'ı temizler

ES_AWAYMODE_REQUIRED
Ekran kararır ancak bilgisayar uykuya geçmez.

Ekranı kapatmak
Açıklaması şöyle

SC_MONITORPOWER
0xF170
Sets the state of the display. This command supports devices that have power-saving features, such as a battery-powered personal computer.
The lParam parameter can have the following values:
  • -1 (the display is powering on)
  • 1 (the display is going to low power)
  • 2 (the display is being shut off)
Şöyle yaparız.
SendMessage(handle, WM_SYSCOMMAND, SC_MONITORPOWER, 2);


1 Ekim 2018 Pazartesi

HLA RTIambassador Arayüzü - Federation Restore Kabiliyeti

Giriş
Yazının ismi RTIambassador Arayüzü ancak hem RTIambassador hem de FederateAmbassador çağrılarını gösteriyor.

requestFederationRestore metodu
Federate için çağrı sırası şöyle.
requestFederationRestore (String label)  -> RTI - 1
requestFederationRestoreSucceded (String label) <- RTI - 2
requestFederationRestoreFailed (String label) <- RTI - 2
federationRestoreBegun () <- RTI - 3
initiateFederateRestore (String label, String federateName) <- RTI - 4
federationRestoreComplete() -> RTI - 5
federationRestoreNotComplete() -> RTI - 5
federationRestored() <- RTI - 6
federationNotRestored () <- RTI - 6
Bu çağrının sonucunda RTI requestFederationRestoreSucceded() metodu ile restore işlemine başlayabileceğini belirtir. Eğer başlayamayacaksa requestFederationRestoreFailed() çağrısını yapar ve akış burada biter.

Federation Save işleminde RTI save işlemine başlayıp başlayamayacağını belirtmiyor. restore işleminde neden bu yapıya ihtiyaç duyulmuş bilmiyorum. Sanırım RTI kendi içinde tutarlılık kontrolleri yapıyor diye düşünüyordum. Ancak save edilmemiş bir labe ile çağrılsa bile bu metod hata dönmüyor!

FederateAmbassador.federationRestoreBegun metodu
HLA thread'i içinde çalılır. Bu metod içinde genellikle bir  başka thread'e Command gönderilir. Yani Command Örüntüsü kullanılır.

RTI'dan bu çağrıyı aldıktan sonra uygulamanın HLA mesajları göndermemesi gerekir. Özellikle yavaş olan katılımcıların bu çağrıdan sonra bir şekilde hesaplama yapmayı durdurması gerekir. Çünkü yapacağı işlemler muhtemelen çöpe gidecektir.

Ben bu kullanım şeklini çok pratik bulmuyorum çünkü hesaplamanın ortasında işlemi bölmek mümkün olmayabilir. Daha pratik bir kullanım şeklinde tüm hesaplamaları halen göndermek ve alıcı tarafta bir kuyrukta biriktirmek olabilir.

FederateAmbassador initiateFederateRestore metodu
HLA thread'i içinde çalılır.  Bu metod içinde genellikle bir  başka thread'e Command gönderilir. Yani Command Örüntüsü kullanılır.

Bu çağrının parametrelerinden bir tanesi federateName. Bu parametre neden gerekli bilmiyorum. Bu çağrı sonucunda  katılımce eski veriyisine geri döner. Eğer geriye sarma işlemi başarılı ise federationRestoreComplete() metodunu çağırır. Başarılı değilse federationRestoreNotComplete() metodunu çağırır.

Tüm katılımcıların geriye sarma işlemi başarılı ise RTI federationRestored() metodunu çağırır. Başarılı değilse federationNotRestored() metodunu çağırır.

Federation Restore işlemi devam ederken updateAttributeValues() çağrısı yapılırsa hla.rt.1516e.exceptions.RestoreInProgress fırlatılır.

FederateAmbassador federationNotRestored  metodu
Hata kodu FEDERATE_REPORTED_FAILURE_DURING_RESTORE olabilir.



28 Eylül 2018 Cuma

ARINC 653 Scheduler

Giriş
Bir çok işletim sisteminde çeşit çeşit scheduler'lar görmek mümkün. Bunların kimisi çok basit bir döngüden ibaret iken, kimisi de gayet karmaşık olabiliyor. Aşağıda bazı scheduler'ların isimileri mevcut.
TASK SCHEDULER TYPETASK EXECUTIONDEVICE I/O METHOD(S)
Endless LoopNo tasks.Polled I/O Only.
Basic Cyclic ExecutiveAs often as possible.  Polled I/O Only.
Time-Driven Cyclic ExecutiveSingle frequency.Polled I/O Only.
Multi-rate Cyclic ExecutiveMultiple frequencies. Polled I/O Only.
Multi-rate Executive for Periodic TasksMultiple frequencies,
 at higher precision
Polled I/O Only.
Multi-rate Executive with InterruptsMultiple frequencies,
at higher precision
Polled and
Interrupt-driven I/O.
Priority-based Preemptive SchedulerPeriodic and
Non-periodic tasks.
Polled and
Interrupt-driven I/O.
Deadline SchedulerPeriodic and Non-periodic tasks.
+Better handling of real-time requirements
Polled and
Interrupt-driven I/O.
Partition SchedulerPeriodic and Non-periodic tasks.
+Better handling of tasks                                           with required execution.
Polled and
Interrupt-driven I/O.


ARINC 653 Scheduler Nasıl Çalışır?
ARINC 653 standardı iki kademeli scheduler tanımlıyor. İlk scheduler Bölümleme Scheduler'ı. Diğeri ise Bölümleme İçindeki Priority-based Preemptive Scheduler. Aşağıda her ikisini de açıklamaya çalıştım.

Bölümleme (Partition) Scheduler Nedir?
Bu scheduler bölümlemeleri çalıştırır. En önemli özelliği her bölümlemeye belirtilen zamanın ayrılacağını garanti eder. Böylece hiç bir bölümleme kendi zamanını aşamaz ve diğer bölümlemeleri mahrum bırakmaz (starvation).

Bölümleme İçi Priority-based Preemptive Scheduler Nedir?
Bölümlemeyi kendi başına çalışan sanal bir bilgisayar gibi düşünebiliriz. Bölümleme içinde priority-based preemptive scheduler çalışır. 

Non Preemptive Scheduling Nedir?
Geçişli zamanlama kavramını tam olarak anlayabilmek için önce tersini bilmek gerekir. Konuyu en iyi açıklayan sayfa burada. Özet olarak, bir uygulama süresi bitinceye veya bloke oluncaya kadar çalışabilir, yüksek önceliğe sahip bir başka uygulama hazır duruma gelince, işini yarıda bırakmaya zorlanamaz.

Preemptive Scheduling Nedir?
Preemptive Scheduling yazısına taşıdım

Önceliğin Tersine Çevrilmesi (Priority Inversion) Nedir?
Geçişli zamanla kullanılan sistemlerde, bazen amacın dışına çıkarak şöyle bir hata yapılabiliyor. Önceliği yüksek olan bir görev, düşük önceliğe sahip bir başka işin kaynağa koyduğu kilit sebebiyle sürekli bloke olabilir, ve bu yüzden görevini yerine getirmeden scheduler tarafından uyutulabilir. Böylece istemeden de olsa öncelikler tersine çevrilmiş olur ve düşük önemdeki iş, yüksek önemdeki işi keserek sürekli önüne geçer.

Önceliği Değiştirilmesi Mümkün mü ?
ARINC 653 bir uygulama yaratıldıktan sonra, önceliğinin değiştirilmesine izin vermez! Dolayısıyla tek atımlık bir kurşun vardır.

Genel Maksatlı Scheduler Nasıl Çalışır?
Çoğu genel maksatlı işletim sisteminde bulunan scheduler adil (fairness) olmayı hedefler. Yani, her uygulamaya az bile olsa işlemci ayrılmaya çalışılır. ARINC 653 bölümleme içindeki scheduler'ın ana amacı adil olmak değildir! Bu scheduler sadece öncelik ve zamana bakar. Dolayısıyla, en düşük önceliğe sahip uygulamaya sıra gelip gelmediği ile ilgilenmez.

Rate Monotonic Scheduling Nedir?
Konunun ARINC 653 ile alakası yok, ancak hazır okumuş ve anlamışken not almak istedim.
Rate Monotonic Scheduling ile periyodu en kısa olan işe en yüksek öncelik tanınır. The shorter the task's period, the higher its priority. Bu yöntemde görevler arasında bağımlılık olmadığı kabul edilir. Aşağıda açıklama mevcut.
Basic rate-monotonic analysis, one of the earlier theories used for determining schedulability – and the subject of one of the 20 most commonly cited papers in computer science – can only guarantee schedulability for tasks that do not share resources.
Cooperative MultiTasking
Sanırım artık bu yöntemi kullanan işletim sistemi kalmadı. Açıklaması şöyle.
Windows 3.1 uses cooperative multi-tasking – meaning that each application that is in the process of running is instructed to periodically check a message queue to find out if any other application is asking for use of the CPU and, if so, to yield control to that application. However, many Windows 3.1 applications would check the message queue only infrequently, or not at all, and monopolize control of the CPU for as much time as they required. A pre-emptive multi-tasking system like Windows 95 will take CPU control away from a running application and distribute it to those that have a higher priority based on the system’s needs.
Bir başka açıklama şöyle.
Preemptive (rather than cooperative) multitasking was a highly-touted feature for PC's in 1996, with its inclusion in Windows 95 for the first time. It was also highly-touted for 2001 Macs when included with OS X. Earlier versions of both these mainstream consumer OS's supported cooperative multitasking.






26 Eylül 2018 Çarşamba

SHA-3

Giriş
Standart SHA-3 algoritmasını belirlemek için 2007 - 2013 yılları arasında bir yarışma düzenlendi. Bu algoritma 224, 256, 384, ve 512 bit uzunluğunda hash çıktısı verir. Açıklaması şöyle
Everything was changed between SHA-2 and SHA-3.

In the specific case of the "length extension attack": the issue is that SHA-2 process data by splitting it into elementary blocks (64 or 128 bytes, depending on the SHA-2 variant), and produces for each block an output which has exactly the same size as the function output. Moreover, the output for a complete message is merely the current output after processing all blocks of the (padded) message. This means that anybody can take a hash output and "continue" processing of a longer message with additional blocks.

In SHA-3, a sponge construction is used. The crucial point is that, in a sponge, the internal state is much larger than the hash function output. Thus, you cannot simply "continue" processing of a message by using a hash output, because that output contains only a fraction of the internal state.

13 Eylül 2018 Perşembe

SQLite Sütun Tipleri

Giriş
Açıklaması şöyle. Numeric tipi, Integer ve Real'in atası gibi düşünülebilir.
SQLite, unlike most other RDBMS, uses a dynamic type system. This means that any of SQLite's fives storage classes can be present in any column, despite that the column belongs to one type. But obviously, it is not best practice to mix types within a single column. For example, mixing numeric and character data in the same column is bad practice, as it would be in any database. The five actual storage classes in SQLite are:

NONE/NULL -
INTEGER
REAL
TEXT
NUMERIC
Affinity
Açıklaması şöyle.
SQLite introduced a concept known as type "affinities." They were introduced in order to maximize compatibility between SQLite and other databases. 
Sütun tipi farklı farklıymış gibi görünse de aslında altta temel tiplerden birisini kullanıyor.

Integer Affinity
Açıklaması şöyle.
Numbers without a decimal component would be assigned to the INTEGER storage class.
Şu tipler olabilir.
INT
INTEGER
TINYINT
SMALLINT
MEDIUMINT
BIGINT
UNSIGNED BIG INT
INT2
INT8

Null Affinity
Şu tipler olabilir.
BLOB
no datatype specified

Numeric Affinity
Şu tipler olabilir.
NUMERIC
DECIMAL(10,5)
BOOLEAN
DATE
DATETIME

Real Affinity
Açıklaması şöyle.
The REAL storage class is used for numeric data with a decimal component.
Şu tipler olabilir.
REAL
DOUBLE
DOUBLE PRECISION
FLOAT

Text Affinity
Şu tipler olabilir.
CHARACTER(20)
VARCHAR(255)
VARYING CHARACTER(255)
NCHAR(55)
NATIVE CHARACTER(70)
NVARCHAR(100)
TEXT
CLOB




11 Eylül 2018 Salı

TCP ve Latency - Gecikme

Giriş
TCP gecikmenin çok olduğu ortamlarda iyi çalışmıyor.

Store-and-Forward Protocol
Açıklaması şöyle.
With TCP, when a router receives a packet, it immediately sends it on to the next hop—or, if it can't, rejects it and sends back an error.

With a store-and-forward protocol, when a router receives a packet, it looks up the next time it expects to be able to talk to the next hop (possibly choosing from among multiple possibilities based on how big the packet is, what its QoS tags say, etc.) and stores it until then.

Store-and-forward goes back to SMTP, NNTP, UUCP, and other protocols from before the public internet.


10 Eylül 2018 Pazartesi

HLA RTIambassador Arayüzü

Giriş
Şu satırı dahil ederiz.
import hla.rti1516.RTIambassador;
Bu arayüz RtiFactoryFactory tarafıdan yaratılır.

createFederationExecution metodu - String + URL
Çağrı sırası şöyle. İlk parametre federasyon ismi, ikinci parametre FOM dosyasıdır. Eğer federasyon mevcutsa hla.rti1561e.exceptions.FederationExecutionAlreadyExists fırlatılır.
createFederationExecution() -> joinFederationExecution()
Örnek
Şöyle yaparız.
String federationName = "...";
URL fomURL = "...";
try {
  rtiAmb.createFederationExecution (federationName, fomURL);
}
catch (FederationExecutionAlreadyExists e) {
 ...
}
destroyFederationExecution metodu
Parametre olarak federasyon ismini alır

disableTimeConstrained metodu
RTIambassador Arayüzü - Time Management yazısına taşıdım.

disableTimeRegulation metodu
RTIambassador Arayüzü - Time Management yazısına taşıdım.

enableTimeConstrained metodu
RTIambassador Arayüzü - Time Management yazısına taşıdım.

enableTimeRegulation metodu
RTIambassador Arayüzü - Time Management yazısına taşıdım.

getAttributeHandle metodu - hla.rti1516.ObjectClassHandle + string
RTIambassador Arayüzü - Declaration Management yazısına taşıdım.

getAttributeHandleSetMapFactory metodu
rtiAmb.publishObjectClassAttributes() veya
rtiAmb.subscribeObjectClassAttributes()

metodları ile sınıfın hangi alanlarını yayınlayacağımızı veya okuyacağımızı belirtirken bu factory trafından üretilen handle nesnelerini kullanarak doldurururz.

Örnek
Şöyle yaparız.
AttributeHandleSetFactory factory=  rtiAmb.getAttributeHandleSetFactory ();
Daha sonra şöyle yaparız.
AttributeHandleSet set=  factory.create ();
Elimizde bir attribute olsun.
AttributeHandle positionAttribute  rtiAmb.getAttributeHandle (...);
Bu attribute nesnesini set'e ekleriz.
set.add (positionAttribute);
Bu nesnenin alanlarını bildirmek için şöyle yaparız.
rtiAmb.publishObjectClassAttributes (set);
getAttributeHandleValueMapFactory metodu
rtiAmb.updateAttributeValues() metodu ile Object gönderirken parametreleri bu factory trafından üretilen handle nesnelerini kullanarak doldurururz.
Örnek
Şöyle yaparız.
AttributeHandleValueMapFactory factory=  rtiAmb.getAttributeHandleValueMapFactory ();
getParameterHandleValueMapFactory metodu
Interaction gönderirken parametreleri bu factory trafından üretilen handle nesnelerini kullanarak doldurururz.
Örnek
Şöyle yaparız.
ParameterHandleValueMapFactory factory=  rtiAmb.getParameterHandleValueMapFactory ();
getObjectClassHandle metodu - string
RTIambassador Arayüzü - Declaration Management yazısına taşıdım.

getTimeFactory metodu
Şöyle yaparız.
LogicalTime time =  rtiAmb.getTimeFactory().makeFinal();
joinFederationExecution metodu
İlk parametre federate ismi, ikinci parametre federation ismi, üçüncü parametre FederateAmbassador arayüzü. Bu arayüz RTI'dan callback almak içindir. Dördüncü parametreyi bilmiyorum ama sanırım  hep null.

publishInteractionClass metodu
RTIambassador Arayüzü - Declaration Management yazısına taşıdım.

publishObjectClassAttributes metodu
RTIambassador Arayüzü - Declaration Management yazısına taşıdım.

registerFederationSynchronizationPoint metodu
RTIambassador Arayüzü - Federation Synchronization yazısına taşıdım.

registerObjectInstance metodu
RTIambassador Arayüzü - Declaration Management yazısına taşıdım.

resignFederationExecution  metodu
RTIambassador Arayüzü - Federation Management yazısına taşıdım.

subscribeInteractionClass metodu
RTIambassador Arayüzü - Declaration Management yazısına taşıdım.

subscribeObjectClassAttributes metodu
RTIambassador Arayüzü - Declaration Management yazısına taşıdım.

synchronizationPointAchieved metodu - string
registerFederationSynchronizationPoint() çağrısı ile ismi belirtilen nokta yaratılır. Diğer federelere ismi belirtilen noktaya erişildiği bildirilir. Tüm federeler bu noktaya varınca FederateAmbassador.federationSynchronized() tetiklenir.
Örnek ver

tick metodu
Örnek ver

timeAdvanceRequest metodu
RTIambassador Arayüzü - Time Management yazısına taşıdım.

updateAttributeValues metodu